Reputation: 13
Im looking to input text into nested cells in word using VBA. I can input into the top level table using the code below but can't input into a nested cell. (There are multiple nested tables).
Any help on how to do this?
ActiveDocument.Tables(1).Cell(Row:=23, Column:=19).Range.Text = ""
Upvotes: 0
Views: 263
Reputation: 1713
You have to test for nested cells and then point to the appropriate cell range. Here is an example.
If Selection.Cells(1).NestingLevel = 2 Then
Selection.Cells(1).Range.Cells(1).Range.Text = "Nested"
Else
Selection.Cells(1).Range.Text = "Not Nested"
End If
Using your example of a table that contains a nested table cell in Row 23, Column 19 the command will look like the following.
ActiveDocument.Tables(1).Cell(23, 19).Range.Cells(1).Range.Text = "123"
I want to emphasize though that you should test that there is actually a nested cell within the given cell range. If you don't, your code could fail.
Upvotes: 1