0

I'm trying to find a way to add lines and information to a prebuilt table in a word document. The table is right now only two lines. The headers and a blank line (2 Columns). How would I go about adding new lines of data to this table. I've tried with bookmarks but I have been unable to get the code to work.

I would give a sample of code but my code just fails so I don't think it would help.

I need to be able to loop through a 2-D array and insert new rows with information from the 2-D array for each time it loops.

Community
  • 1
  • 1
Tolure
  • 859
  • 1
  • 14
  • 34
  • 1
    Even if it doesn't work, posting your code is important to getting a good answer. Your code sample often helps to define more clearly what you are trying to accomplish. – Stewbob Jun 13 '13 at 10:44
  • see http://stackoverflow.com/questions/3567441/extract-data-from-word-document-to-an-excel-spreadsheet/3611739#3611739 and http://stackoverflow.com/questions/5550959/excel-macro-pasting-text-from-excel-in-word-header/5555442#5555442 – MikeD Jun 13 '13 at 12:56

1 Answers1

2

This is the basic syntax for inserting data into a pre-existing table in Word, from VBA in Excel:

Dim doc As Word.Document
Set doc = GetObject("path to my word document")

With doc.Tables(IndexNumberOfTableYouWant)
  .Cell(DesiredRow, 1).Range.Text = "my column 1 information"
  .Cell(DesiredRow, 2).Range.Text = "my column 2 information"
End With

As long as the proper number of columns is predefined, you can just keep adding rows by incrementing the DesiredRow variable, and Word will append those rows to the table automatically.

Stewbob
  • 16,759
  • 9
  • 63
  • 107