Code:
Option Explicit
Sub DummyTable()
Dim minp As Variant
Dim maxp As Variant
Dim pt(2) As Double
Dim acTable As AcadTable
Dim pickPt As Variant
pickPt = ThisDrawing.Utility.GetPoint(, vbLf & "Enter a table inserion point: ")
pt(0) = pickPt(0): pt(1) = pickPt(1): pt(2) = 0#
Set acTable = ThisDrawing.ActiveLayout.Block.AddTable(pt, 10, 4, 10, 60)
With acTable
.RegenerateTableSuppressed = True
.RecomputeTableBlock False
.TitleSuppressed = False
.HeaderSuppressed = False
.SetTextStyle AcRowType.acTitleRow, "Standard" '<-- change text style name here
.SetTextStyle AcRowType.acHeaderRow, "Standard"
.SetTextStyle AcRowType.acDataRow, "Standard"
Dim i As Double, j As Double
Dim col As New AcadAcCmColor
col.SetRGB 255, 0, 255
'title
.SetCellTextHeight i, j, 6.4
.SetCellAlignment i, j, acMiddleCenter
col.SetRGB 194, 212, 235
.SetCellBackgroundColor i, j, col
col.SetRGB 127, 0, 0
.SetCellContentColor i, j, col
.SetCellType i, j, acTextCell
.SetText 0, 0, "Table Title"
i = i + 1
'headers
For j = 0 To .Columns - 1
col.SetRGB 203, 220, 183
.SetCellBackgroundColor i, j, col
col.SetRGB 0, 0, 255
.SetCellContentColor i, j, col
.SetCellTextHeight i, j, 5.2
.SetCellAlignment i, j, acMiddleCenter
.SetCellType i, j, acTextCell
.SetText i, j, "Header" & CStr(j + 1)
Next
'data rows
For i = 2 To .Rows - 1
For j = 0 To .Columns - 1
.SetCellTextHeight i, j, 4.5
.SetCellAlignment i, j, acMiddleCenter
If i Mod 2 = 0 Then
col.SetRGB 239, 235, 195
Else
col.SetRGB 227, 227, 227
End If
.SetCellBackgroundColor i, j, col
col.SetRGB 0, 76, 0
.SetCellContentColor i, j, col
.SetCellType i, j, acTextCell
.SetText i, j, "Row" & CStr(i - 1) & " Column" & CStr(j + 1)
Next j
Next i
' set color for grid
col.SetRGB 0, 127, 255
.SetGridColor AcGridLineType.acHorzBottom, AcRowType.acTitleRow, col
.SetGridColor AcGridLineType.acHorzInside, AcRowType.acTitleRow, col
.SetGridColor AcGridLineType.acHorzTop, AcRowType.acTitleRow, col
.SetGridColor AcGridLineType.acVertInside, AcRowType.acTitleRow, col
.SetGridColor AcGridLineType.acVertLeft, AcRowType.acTitleRow, col
.SetGridColor AcGridLineType.acVertRight, AcRowType.acTitleRow, col
.SetGridColor AcGridLineType.acHorzBottom, AcRowType.acHeaderRow, col
.SetGridColor AcGridLineType.acHorzInside, AcRowType.acHeaderRow, col
.SetGridColor AcGridLineType.acHorzTop, AcRowType.acHeaderRow, col
.SetGridColor AcGridLineType.acVertInside, AcRowType.acHeaderRow, col
.SetGridColor AcGridLineType.acVertLeft, AcRowType.acHeaderRow, col
.SetGridColor AcGridLineType.acVertRight, AcRowType.acHeaderRow, col
.SetGridColor AcGridLineType.acHorzBottom, AcRowType.acDataRow, col
.SetGridColor AcGridLineType.acHorzInside, AcRowType.acDataRow, col
.SetGridColor AcGridLineType.acHorzTop, AcRowType.acDataRow, col
.SetGridColor AcGridLineType.acVertInside, AcRowType.acDataRow, col
.SetGridColor AcGridLineType.acVertLeft, AcRowType.acDataRow, col
.SetGridColor AcGridLineType.acVertRight, AcRowType.acDataRow, col
'set line weights for grid
.SetGridLineWeight AcGridLineType.acVertLeft, AcRowType.acTitleRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acVertRight, AcRowType.acTitleRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acHorzTop, AcRowType.acTitleRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acHorzBottom, AcRowType.acHeaderRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acHorzInside, AcRowType.acHeaderRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acHorzTop, AcRowType.acHeaderRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acVertInside, AcRowType.acHeaderRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acVertLeft, AcRowType.acHeaderRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acVertRight, AcRowType.acHeaderRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acHorzBottom, AcRowType.acDataRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acHorzInside, AcRowType.acDataRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acHorzTop, AcRowType.acDataRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acVertInside, AcRowType.acDataRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acVertLeft, AcRowType.acDataRow, AcLineWeight.acLnWt040
.SetGridLineWeight AcGridLineType.acVertRight, AcRowType.acDataRow, AcLineWeight.acLnWt040
.RegenerateTableSuppressed = False
.RecomputeTableBlock True
.Update
.GetBoundingBox minp, maxp
ZoomWindow minp, maxp
ZoomScaled 0.9, acZoomScaledRelative
ThisDrawing.SetVariable "LWDISPLAY", 1
Set col = Nothing
End With
MsgBox "Done"
End Sub