Fill a table in Word Template with VBA?

I am filling out a Word template with data that was collected from user input. In particular, a (variable) number of documents is selected, and information about each document fills the row of the table.

I bookmarked several elements in the template and successfully filled in the header information from my macro, but I'm not so sure about the table. I bookmarked the first cell and tried to tab (using Chr (9)), and also tried to pass an array. (In a template, a table has only the first row. Typically, tabbing for the last column creates an additional row.)

I can save the contents of the cell with

   Word.Application.ActiveDocument.Tables(1).Cell(3, 1).Range.Text

but can’t write to any cell except the first, where I placed a bookmark.

Can anyone suggest a possible solution to populate the table?

+3
source share
2 answers

Use this code to populate the table.

ActiveDocument.Tables(1).Cell(1, 1).Range.Text = "Blah Blah"

This will be written to the first cell in the first table. Use a loop to fill in the remaining cells.

I would also recommend this link.

Topic: Automating Word Tables to Insert and Extract Data

Link : http://msdn.microsoft.com/en-us/library/aa537149%28v=office.11%29.aspx#Y1254

Eject

Summary. Learn how to automate the creation and formatting of tables in Word. Get information on optimizing performance, populating a table with data, formatting a table structure, linking table data, and extracting data from a table. (25 printed pages)

+6

, Access Word. , Word VBA script, Word . , . , , , , . - , .

0

All Articles