PowerDesigner VBA to create tables and columns

Source: Internet
Author: User
Tags powerdesigner

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

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.