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