Getting a handle on a Cell in a table

G

GrantS

I am trying to populate three Word tables using code that has
retrieved data from a database. These tables reside in the document
that I am now making into a Template with VBA code to perform various
things such as data access.

I know that you can return data and build a string using vbTab to
delimit the fields and crlf to indicate new lines. The string can then
be inserted in a range from a chosen bookmark in the Word Document.
This range can then be converted to table and then the table
formatted.

I am wanting to use the current tables which have the necessary
headings and the heading and cells and column widths formatted.
Therefore. I want to place the data beginning at Cell (2,1) = row 2
Col1. I wanted then to loop through the recordset and place the data
in the remainder of the cells one by one. With Visual basic datagrids
can be populated by building a string and using VBTab as the cell
delimiters. This does not work in Word. Is there some similar way of
achieving this in Word.

The tables I need to populate already exist and are correctly
formatted with the first row being the header.

I want to get a handle of the already existing table OR get a handle
of the C(2,1) Cell through a bookmark placed in this cell. Once I have
the handle of this cell, I can then begin looping across the columns
and then down the rows and populate the cells.

This way will hopefully avoid the need to adjust the column widths
once the data is entered as these are already set in the "empty"
table.


Has anyone any code snippets or pointers in this regard? Will there be
any problems with performance the way I am trying to achieve this (3
Tables 5 columns - Average 20 cells.

Hope someone can help. Thanks.

Grant
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Grant,

ActiveDocument.Tables(n).Cell(Rownum, Colnum).Range can be used to populate
a particular cell in a table.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top