Word VBA, Modify Table Data

In this article I will explain how you can use VBA to modifytable‘s data in word. If there are multiple tables in a word document the first thing to do is to determine which table you are going to modify. Basically tables are indexed starting from one. So the first table will have the index “1”, the second table will have the index “2”  and so on. You can get a reference to the table using the code below:

ThisDocument.Tables.Item(1)

The code above gives reference to the first table in the document. Using the code below you will be able to change the text in row 1 column 1 of the table:

ThisDocument.Tables.Item(1).Cell(1, 1).Range = "New Data"

 Result:

Word VBA, Fill Table Data, Result

The code below adds the text “More Data” to column 4, row 2 of the 3rd table:

ThisDocument.Tables.Item(3).Cell(2, 4).Range = "More Data"

Result:

Word VBA, Fill Table Data, Result, 2
You can download the file and code related to this article from the link below:

See also:

If you need assistance with your code, or you are looking for a VBA programmer to hire feel free to contact me. Also please visit my website  www.software-solutions-online.com

Leave a Reply

Your email address will not be published. Required fields are marked *