T
tborthwick
Hello,
I have a script that reads several items in a loop and creates a
header then a table for each. The header and the table text should
have different styles, but all the text gets the style I first set for
the header. In the script below you can see I try to set the font size
to 10 before adding a table, but the size stays at 12, which is set
earlier. Is it because I'm using the same range? I tried using two
range variable, one for the header and one for the table, but it
didn't change anything. Any help would be appreciated.
Thanks,
Tom
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
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)
'Write out header
Set myRange = ActiveDoc.Range
myRange.Font.Size = 12
myRange.Collapse 0
myRange.InsertAfter ent.EntityName & vbCrLf
If ent.Note <> "" Then
Set myRange = ActiveDoc.Range
myRange.Collapse 0
myRange.Font.Size = 10
myRange.InsertAfter ent.Note & 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 = "Notes"
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.Notes
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
End Sub
I have a script that reads several items in a loop and creates a
header then a table for each. The header and the table text should
have different styles, but all the text gets the style I first set for
the header. In the script below you can see I try to set the font size
to 10 before adding a table, but the size stays at 12, which is set
earlier. Is it because I'm using the same range? I tried using two
range variable, one for the header and one for the table, but it
didn't change anything. Any help would be appreciated.
Thanks,
Tom
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
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)
'Write out header
Set myRange = ActiveDoc.Range
myRange.Font.Size = 12
myRange.Collapse 0
myRange.InsertAfter ent.EntityName & vbCrLf
If ent.Note <> "" Then
Set myRange = ActiveDoc.Range
myRange.Collapse 0
myRange.Font.Size = 10
myRange.InsertAfter ent.Note & 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 = "Notes"
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.Notes
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
End Sub