Powerdesigner vba creates tables and columns, powerdesignervba

Source: Internet
Author: User
Tags powerdesigner

Powerdesigner vba creates tables and columns, powerdesignervba

Creating powerdesigner tables and columns manually is very troublesome. Therefore, we need to use vba for implementation. We can refer to http://www.pudn.com/downloads447/sourcecode/database/detail1884121.html for reference:

Create a table:

Set mdl = ActiveModel

Set table = mdl. Tables. CreateNew

Table. Name = "tablename"

Table. Code = "table"

Create a column:

For each Tab in folder. tables
Dim col
Set col = tab. columns. createnew
Col. name = "columnname"
Col. code = "columnname"
Col. comment = "columncomment"
Col. datatype = "nvarchar2 (255 )"
Next


The source code is as follows:

Option Explicit


Dim mdl 'the current model
Set mdl = ActiveModel
If (mdl Is Nothing) Then
MsgBox "There is no Active Model"
End If


Dim HaveExcel
Dim RQ
RQ = vbYes 'msgbox ("Is Excel Installed on your machine? ", VbYesNo + vbInformation," Confirmation ")
If RQ = vbYes Then
HaveExcel = True
'Open & Create Excel Document
Dim x1'
Set x1 = CreateObject ("Excel. Application ")
X1.Workbooks. Open "test.xls"
X1.Workbooks (1). Worksheets ("sheet1"). Activate
Else
HaveExcel = False
End If


A x1, mdl


Sub a (x1, mdl)
Dim rwIndex
Dim tableName
Dim colname
Dim table
Dim col
Dim count


On error Resume Next
For rwIndex = 2 To 20000
With x1.Workbooks (1). Worksheets ("sheet1 ")
If trim (. Cells (rwIndex, 2). Value) = "" Then
Exit
End If
If trim (. Cell (rwIndex, 2). Value) <> trim (. Cells (rwindex-1, 2). value) Then
Set table = mdl. Tables. CreateNew
Table. Name = trim (. Cells (rwIndex, 1). Value)
Table. Code = trim (. Cells (rwIndex, 2). Value)
Count = count + 1
'Create a table Loop
'-------------------- First column Loop
'Colname =. Cells (rwIndex, 3). Value
Set col = table. Columns. CreateNew
'Msgbox. Cells (rwIndex, 1). Value, vbOK + vbInformation, "column"
Col. Name = trim (. Cells (rwIndex, 3). Value)
'Msgbox col. Name, vbOK + vbInformation, "column"
Col. Code = trim (. Cells (rwIndex, 4). Value)

If trim (. Cells (rwIndex, 10). Value) <> "" Then
Col. Comment = "unit:" +. Cells (rwIndex, 10). Value + ". "+. Cells (rwIndex, 18). Value
Else
Col. Comment =. Cells (rwIndex, 8). Value
End if

If trim (. Cells (rwIndex, 6). Value) <> "" Then
Col. Primary = true
End if

Col. datatype = trim (. Cells (rwIndex, 5). Value)







'--------------- First column Loop
Else
'---------------- Column Loop
'Colname =. Cells (rwIndex, 4). Value
Set col = table. Columns. CreateNew
'Msgbox. Cells (rwIndex, 1). Value, vbOK + vbInformation, "column"
Col. Name = trim (. Cells (rwIndex, 3). Value)
'Msgbox col. Name, vbOK + vbInformation, "column"
Col. Code = trim (. Cells (rwIndex, 4). Value)

If trim (. Cells (rwIndex, 10). Value) <> "" Then
Col. Comment = "unit:" +. Cells (rwIndex, 10). Value + ". "+. Cells (rwIndex, 18). Value
Else
Col. Comment =. Cells (rwIndex, 8). Value
End if

If trim (. Cells (rwIndex, 6). Value) <> "" Then
Col. Primary = true
End if

Col. datatype = trim (. Cells (rwIndex, 5). Value)




End If
End
Next
MsgBox "total data table structure generation" + CStr (count), vbOK + vbInformation, "table"


Exit Sub
End sub

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.