Thread: [Solved] Table won't create
View Single Post
 
Old 02-22-2017, 03:08 PM
pbassett pbassett is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Feb 2017
Posts: 6
pbassett is on a distinguished road
Default Table won't create

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

Last edited by pbassett; 02-22-2017 at 03:15 PM. Reason: Added attachment
Reply With Quote