Reputation: 371
I have tables that I am creating, and I want to be able to modify them through the code in the VBA.
What I need to do to the tables is merge and resize some cells and also add text to some of the cells.
Upvotes: 3
Views: 39589
Reputation: 8699
To append on what Lance was saying, here's an example of Merging Cells and setting text in the value of those merged cells:
Dim myCells As Range
With ActiveDocument
Set myCells = .Range(Start:=.Tables(1).Cell(1, 1).Range.Start, End:=.Tables(1).Cell(1, 3).Range.End)
myCells.Select
End With
Selection.Cells.Merge
ActiveDocument.Tables(1).Cell(Row:=1, Column:=1).Range.Text = "Value for Merged Cells"
NOTE: The table in this example had three columns and two rows
Upvotes: 5
Reputation: 22842
You need to access the Table object, like
ActiveDocument.Tables(1).Cell(Row:=2, Column:=2).Range.Text
or
<some Word.Document here>.
Content.Tables(1).Columns.SetWidth <columnwidthhere>, wdAdjustSameWidth
Upvotes: 3