Manually set up PowerDesigner tables and columns is very troublesome, so think with VBA implementation, reference http://www.pudn.com/downloads447/sourcecode/database/detail1884121.html, as follows:
To create a table:
Set mdl = Activemodel
Set table = mdl. Tables.createnew
Table. Name = "TableName"
Table. Code = "Table"
To create a column:
For all 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
Refer to the following source code:
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 for
End If
If Trim (. Cells (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
' Build a table cycle
'--------------------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 Loops
' 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 with
Next
MsgBox "Generate data table structure Total" + CStr (count), vbOK + vbinformation, "table"
Exit Sub
End Sub
PowerDesigner VBA to create tables and columns