I want to loop thru a dbf and create word table for each record meeting the condition, and I got a one-page report with only the last rec in a single table. Look like all records are written to the same table. I tried to use n = n + 1 to place the variable as an element to the table oTable = oDoc.tables[n] But seems it only support numerical rather than variable ?
Asked
Active
Viewed 58 times
1 Answers
0
You have to add each table as you go, making sure to leave space in between them (because Word likes to combine tables).
You'll need something like this inside your loop:
* Assumes you start with oDoc pointing to the document,
* oRange set to an empty range at the beginning of the area where you want to add the tables,
* and that nRows and nCols give you the size of the table.
oTable = oDoc.Tables.Add(m.oRange, m.nRows, m.nCols)
oRange = oTable.Range()
oRange.Collapse(0)
oRange.InsertParagraphAfter()
oRange.Collapse(0)
After this code, you can use oTable to add the data you want to add. Then, on the next time through the loop, you're ready to add another table below the one you just filled.

Tamar E. Granor
- 3,817
- 1
- 21
- 29
-
Oh, I finally can meet the author of my favourite book. thank you very much. – user3876120 Jul 26 '14 at 02:14
-
Lovely to here that it's your favorite book. Glad I could help. – Tamar E. Granor Jul 28 '14 at 20:51