Originally Posted by
MikeJarosz
I would not have used the for...next loop if I could find a better way to grab a table. Apparently there is no AcadTables collection with an Item() property.
You can use DXF group code value pair to create a collection of AcadTables in the drawing instead of looping through the drawing.
I just rearranged your code and it works fine upto a text height of 6. I think text with height of 8 can not be accommodated in a cell of 16 high ( I tried it manually). Here goes the code...
Code:
Dim DwgIndex As AcadTable
Dim TemplateFileName As String
Dim Entity As AcadEntity
Dim CurrentRow As Long
For Each Entity In ThisDrawing.PaperSpace
If TypeOf Entity Is AcadTable Then
Set DwgIndex = Entity
Exit For
End If
Next Entity
DwgIndex.RecomputeTableBlock False
'rows and cols are zero based
CurrentRow = 4
With DwgIndex
.HorzCellMargin = 0
.VertCellMargin = 0
.MergeCells CurrentRow, (CurrentRow + 1), 0, 2
.SetRowHeight CurrentRow, 8
.SetRowHeight CurrentRow + 1, 8
.SetCellTextHeight CurrentRow, 0, 6
.SetCellAlignment CurrentRow, 0, acMiddleCenter
.SetCellTextStyle CurrentRow, 0, "titles"
.SetText CurrentRow, 0, "HEADER"
End With
The interesting thing is that even after merging, CurrentRow refers to the first raw used for merging and CurrentRow+1 refers to the second one. There should be some method for refreshing the table after purging which I was unable to find out. Unfortunately I haven't done anything on AcadTable before.
HTH