T
tborthwick
Hello,
I'm trying to add a table of contents to the word doc my script below
is generating. In the body of the script, I try to mark each entity
name as a TOC entry, then add the TOC to the doc at the end. All I get
is a 'No table of contents found' inserted into my doc. Do I need to
apply a style to the text I want to be toc entries or is there a
problem with the ranges? Any help would be appreciated.
Thanks,
Tom
'MACRO TITLE: EXPORT MODEL META DATA TO WORD
Dim attr As AttributeObj
Dim myRange As Object
Sub Main
Dim Word As Object
Dim Docs As Object
Dim WordBasic As Object
Dim ActiveDoc As Object
Dim diag As Diagram
Dim mdl As Model
Dim sm As SubModel
Dim so As SelectedObject
Dim id As Integer
Dim ent As Entity
Dim attr As AttributeObj
Dim tableCount As Integer
Set Word = CreateObject("Word.Application")
Word.Visible = True
Word.Options.CheckGrammarAsYouType = False
Word.Options.CheckSpellingAsYouType = False
Set ActiveDoc = Word.Documents.Add()
Set diag = DiagramManager.ActiveDiagram
Set mdl = diag.ActiveModel
Set sm = mdl.ActiveSubModel
For Each so In sm.SelectedObjects
If so.Type = 1 Then
id = so.ID
Set ent = mdl.Entities.Item(id)
Set myRange = ActiveDoc.Range
myRange.Font.Size = 12
myRange.Collapse 0
myRange.InsertAfter ent.EntityName & vbCrLf
ActiveDoc.TablesOfContents.MarkEntry Range:=myRange, _
Level:=1, Entry:=ent.EntityName
If ent.Definition <> "" Then
Set myRange = ActiveDoc.Range
myRange.Collapse 0
'myRange.Font.Size = 10
myRange.InsertAfter ent.Definition & vbCrLf
End If
Set myRange = ActiveDoc.Range
'myRange.Font.Size = 10
myRange.Collapse 0
Set objTable = myRange.Tables.Add(Range:=myRange,
NumRows:=ent.Attributes.Count, NumColumns:=3)
Dim curRow As Integer
curRow = 1
'Add column headings
objTable.Cell(curRow, 1).Range.Text = "Column name"
objTable.Cell(curRow, 2).Range.Text = "Datatype"
objTable.Cell(curRow, 3).Range.Text = "Definition"
curRow = curRow + 1
For Each attr In ent.Attributes
objTable.Cell(curRow, 1).Range.Text = attr.ColumnName
objTable.Cell(curRow, 2).Range.Text = Datatype(attr.Datatype,
attr.DataLength)
objTable.Cell(curRow, 3).Range.Text = attr.Definition
curRow = curRow + 1
Next
'4, 27, 36
objTable.autoFormat(36)
objTable.Columns(1).Width = 135
objTable.Columns(2).Width = 80
objTable.Columns(3).Width = 235
Set myRange = ActiveDoc.Range
myRange.Collapse 0
myRange.InsertAfter vbCrLf
End If
Next
For Each table In ActiveDoc.Tables
table.Range.Font.Size = 10
table.Cell(1,1).Range.Font.Bold = True
table.Cell(1,2).Range.Font.Bold = True
table.Cell(1,3).Range.Font.Bold = True
table.Cell(1,1).Shading.BackgroundPatternColorIndex = 475
table.Cell(1,2).Shading.BackgroundPatternColorIndex = wdGray25
table.Cell(1,3).Shading.BackgroundPatternColorIndex = wdGray25
Next
Set tocRange = ActiveDoc.Range(Start:=0, End:=0)
ActiveDoc.TablesOfContents.Add Range:=tocRange, _
UseFields:=False, UseHeadingStyles:=True, _
LowerHeadingLevel:=3, _
UpperHeadingLevel:=1
ActiveDoc.TablesOfContents(1).UpdatePageNumbers
End Sub
Function Datatype ( DT As String , attr As Integer) As String
Dim test As String
test = UCase(DT)
Select Case test
'Case "VARCHAR","CHAR","NCHAR","BIT","TEXT", "DECIMAL","DECIMALN"
Case "VARCHAR","CHAR","NCHAR"
Dim dataLength As String
dataLength = Str(attr)
Datatype = DT & "(" & dataLength & ")"
Case Else
Datatype = DT
End Select
End Function
I'm trying to add a table of contents to the word doc my script below
is generating. In the body of the script, I try to mark each entity
name as a TOC entry, then add the TOC to the doc at the end. All I get
is a 'No table of contents found' inserted into my doc. Do I need to
apply a style to the text I want to be toc entries or is there a
problem with the ranges? Any help would be appreciated.
Thanks,
Tom
'MACRO TITLE: EXPORT MODEL META DATA TO WORD
Dim attr As AttributeObj
Dim myRange As Object
Sub Main
Dim Word As Object
Dim Docs As Object
Dim WordBasic As Object
Dim ActiveDoc As Object
Dim diag As Diagram
Dim mdl As Model
Dim sm As SubModel
Dim so As SelectedObject
Dim id As Integer
Dim ent As Entity
Dim attr As AttributeObj
Dim tableCount As Integer
Set Word = CreateObject("Word.Application")
Word.Visible = True
Word.Options.CheckGrammarAsYouType = False
Word.Options.CheckSpellingAsYouType = False
Set ActiveDoc = Word.Documents.Add()
Set diag = DiagramManager.ActiveDiagram
Set mdl = diag.ActiveModel
Set sm = mdl.ActiveSubModel
For Each so In sm.SelectedObjects
If so.Type = 1 Then
id = so.ID
Set ent = mdl.Entities.Item(id)
Set myRange = ActiveDoc.Range
myRange.Font.Size = 12
myRange.Collapse 0
myRange.InsertAfter ent.EntityName & vbCrLf
ActiveDoc.TablesOfContents.MarkEntry Range:=myRange, _
Level:=1, Entry:=ent.EntityName
If ent.Definition <> "" Then
Set myRange = ActiveDoc.Range
myRange.Collapse 0
'myRange.Font.Size = 10
myRange.InsertAfter ent.Definition & vbCrLf
End If
Set myRange = ActiveDoc.Range
'myRange.Font.Size = 10
myRange.Collapse 0
Set objTable = myRange.Tables.Add(Range:=myRange,
NumRows:=ent.Attributes.Count, NumColumns:=3)
Dim curRow As Integer
curRow = 1
'Add column headings
objTable.Cell(curRow, 1).Range.Text = "Column name"
objTable.Cell(curRow, 2).Range.Text = "Datatype"
objTable.Cell(curRow, 3).Range.Text = "Definition"
curRow = curRow + 1
For Each attr In ent.Attributes
objTable.Cell(curRow, 1).Range.Text = attr.ColumnName
objTable.Cell(curRow, 2).Range.Text = Datatype(attr.Datatype,
attr.DataLength)
objTable.Cell(curRow, 3).Range.Text = attr.Definition
curRow = curRow + 1
Next
'4, 27, 36
objTable.autoFormat(36)
objTable.Columns(1).Width = 135
objTable.Columns(2).Width = 80
objTable.Columns(3).Width = 235
Set myRange = ActiveDoc.Range
myRange.Collapse 0
myRange.InsertAfter vbCrLf
End If
Next
For Each table In ActiveDoc.Tables
table.Range.Font.Size = 10
table.Cell(1,1).Range.Font.Bold = True
table.Cell(1,2).Range.Font.Bold = True
table.Cell(1,3).Range.Font.Bold = True
table.Cell(1,1).Shading.BackgroundPatternColorIndex = 475
table.Cell(1,2).Shading.BackgroundPatternColorIndex = wdGray25
table.Cell(1,3).Shading.BackgroundPatternColorIndex = wdGray25
Next
Set tocRange = ActiveDoc.Range(Start:=0, End:=0)
ActiveDoc.TablesOfContents.Add Range:=tocRange, _
UseFields:=False, UseHeadingStyles:=True, _
LowerHeadingLevel:=3, _
UpperHeadingLevel:=1
ActiveDoc.TablesOfContents(1).UpdatePageNumbers
End Sub
Function Datatype ( DT As String , attr As Integer) As String
Dim test As String
test = UCase(DT)
Select Case test
'Case "VARCHAR","CHAR","NCHAR","BIT","TEXT", "DECIMAL","DECIMALN"
Case "VARCHAR","CHAR","NCHAR"
Dim dataLength As String
dataLength = Str(attr)
Datatype = DT & "(" & dataLength & ")"
Case Else
Datatype = DT
End Select
End Function