How do I create a table with a set number of columns but indefinite number of lines in Microsoft Word, and populate each row by looping through an array?
create table in microsoft word
Collapse
X
-
Tags: None
-
Bump bump...
...I really need help with this. I want to enter some information into textboxes to insert it into a list in a userform, and then take every item in the list and write a table row for it in a table in Microsoft Word. I can probably figure out a way to get the data from the userform into an array, but how do I get the data from the array into the Word table? -
I found it!
I created the first row of the tables directly in Word (which didn't matter, since it only contained column headers), and then used the following code to insert data into the cells:
[CODE=vb] Dim tblItems As Word.Table
Set tblItems = appWord.ActiveD ocument.Tables( 4)
' my table was the fourth to appear in the word document
tblItems.Rows.A dd ' to add a row
tblItems.Cell(t blItems.Rows.Co unt, 2).Range.Text = "hello world" ' to insert the text "hello world" into the second column of the last row[/CODE]Comment
-
Excellent!Originally posted by BlackMustardI found it!
I'm sorry to see you didn't get any response to your question. We try to tackle everything that comes our way, but our VB "staff" are seriously overworked at the moment.
I use the word "staff" loosely, of course - this is entirely a volunteer forum. The experts are generally just people who came here to ask a question and decided to stick around and provide answers.
Thanks for posting the answer you found. This will be helpful for the next person who comes looking for the info.Comment
Comment