I'm working on a macro to export data from Outlook to Word tables. Can
anyone tell me how to move the insertion point (insert text in) a specific
table cell? I assume it is based on table index, row index, and column
index?
Thanks,
Jim
Hi Jim,
Well, you *can* use the table index, row index, and column index if
you know the values you want, but there are several other ways.
If you do know the index values, you don't have to move the insertion
point to that cell in order to insert text. VBA isn't limited to
entering text at the insertion point, and it's often better if you use
a different method.
First, the thing you were thinking of:
ActiveDocument.Tables(tableindex).Cell(rowindex, columnindex).Select
Selection.TypeText stringdata
Without moving the insertion point (the space and underscore at the
end of the first line mean that the statement continues onto the next
line):
ActiveDocument.Tables(tableindex).Cell(rowindex, columnindex) _
.Range.Text = stringdata
If you don't know the right index values, you may be able to use a
find (or possibly a replace) to locate the proper cell. That depends
on there being something unique in that cell, or maybe in an adjacent
cell, that distinguishes it from all other cells.
If you're working from a template, you may be able to put a bookmark
in the proper cell in the template so that it also occurs in each
document based on the template. Then you can insert text at the
bookmark -- regardless of whether it's in a table or in plain text:
ActiveDocument.Bookmarks("bkmkname").Range.Text = stringdata
And if you want the bookmark to enclose the inserted text so it can be
replaced again later, you need the technique shown at
http://www.word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm.