R
ryan_eng
Hi all,
I am writing some vba code to insert a table at a specific bookmark. So far
I have succeeded at doing the following:
-insert table at bookmark with 4 rows, 4 columns.
-set autoformat with a small variation to header row
-merge cells in row 2 and insert test
Now I want to center the text in the merged cell of row 2 but I can't seem
to find the command on the internet. Help!
My code so far is below:
Sub CreateNewTable()
Dim docActive As Document
Dim tblNew As Table
Dim celTable As Cell
Set docActive = ActiveDocument
Set tblNew = docActive.Tables.Add( _
Range:=docActive.Bookmarks("table1").Range, NumRows:=3, _
NumColumns:=4)
With ActiveDocument.Tables(1)
.Cell(Row:=1, Column:=1).Range.InsertAfter Text:="Document No."
.Cell(Row:=1, Column:=2).Range.InsertAfter Text:="Rev."
.Cell(Row:=1, Column:=3).Range.InsertAfter Text:="Date"
.Cell(Row:=1, Column:=4).Range.InsertAfter Text:="Description"
.Cell(Row:=2, Column:=1).Range.InsertAfter Text:="Installation
Documents"
End With
tblNew.AutoFormat Format:=wdTableFormatGrid1, _
ApplyBorders:=True, ApplyFont:=True, ApplyColor:=True
With ActiveDocument.Tables(1)
.Rows(1).Range.Font.Bold = True
.Rows(2).Cells.Merge
End With
End Sub
I am writing some vba code to insert a table at a specific bookmark. So far
I have succeeded at doing the following:
-insert table at bookmark with 4 rows, 4 columns.
-set autoformat with a small variation to header row
-merge cells in row 2 and insert test
Now I want to center the text in the merged cell of row 2 but I can't seem
to find the command on the internet. Help!
My code so far is below:
Sub CreateNewTable()
Dim docActive As Document
Dim tblNew As Table
Dim celTable As Cell
Set docActive = ActiveDocument
Set tblNew = docActive.Tables.Add( _
Range:=docActive.Bookmarks("table1").Range, NumRows:=3, _
NumColumns:=4)
With ActiveDocument.Tables(1)
.Cell(Row:=1, Column:=1).Range.InsertAfter Text:="Document No."
.Cell(Row:=1, Column:=2).Range.InsertAfter Text:="Rev."
.Cell(Row:=1, Column:=3).Range.InsertAfter Text:="Date"
.Cell(Row:=1, Column:=4).Range.InsertAfter Text:="Description"
.Cell(Row:=2, Column:=1).Range.InsertAfter Text:="Installation
Documents"
End With
tblNew.AutoFormat Format:=wdTableFormatGrid1, _
ApplyBorders:=True, ApplyFont:=True, ApplyColor:=True
With ActiveDocument.Tables(1)
.Rows(1).Range.Font.Bold = True
.Rows(2).Cells.Merge
End With
End Sub