I don't know why this code does NOT create a table, even though it did in Record Macro mode, which is how I got the code!
As I stepped through this, the only thing that worked was selecting the bookmark (i.e. it navigated into the existing cell in which I had already defined a bookmark. The
Tables.add command didn't do anything!
How could this not work when the macro did? The table needs to be in the
Due in Next 30 Days cell in the attachment.
wdApp.ActiveDocument.Bookmarks("Table_5").Select
wdApp.ActiveDocument.Tables.add Range:=Selection.Range, NumRows:=2, NumColumns:= _
3, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.ApplyStyleRowBands = True
.ApplyStyleColumnBands = False
End With
Selection.TypeText Text:="Due Date"
Selection.MoveRight unit:=wdCell
Selection.TypeText Text:="Staff Name"
Selection.MoveRight unit:=wdCell
Selection.TypeText Text:="Supervisor"
Selection.MoveRight unit:=wdCell
NVCITable.PNG