Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

Position insertion point in specific table cell

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jim Boyce - 16 Mar 2005 20:16 GMT
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
Jay Freedman - 17 Mar 2005 02:46 GMT
>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
[quoted text clipped - 4 lines]
>
>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.

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org
Jim Boyce - 17 Mar 2005 16:37 GMT
Jay, thanks for the excellent response. Exactly what I needed to know - Jim
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.