• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • Last Modified:

How to reference a table in Word other than by index number.

I am creating an MS Word document through automation from  an MS Access form. In this Word document I insert multiple .dot templates containing predefined tables using the following code:

wordobj.Selection.InsertFile FileName := file name ....

My question is, since the number of tables (.dot templates) that get inserted varies depending on existing data , how do I reference each table other than by its index number. I need to be able to bounce back and forth between tables. Currently I'm using the following code to reference a particular cell within a table:

wordobj.ActiveDocument.Tables(9).Cell(x,y).Select
wordobj.Selection.Collapse

However, this hard-coded index reference assumes that all previous tables have been inserted which may not always be the case.

Thanks in advance,
Don
0
ewingdj
Asked:
ewingdj
  • 2
  • 2
  • 2
1 Solution
 
Chris BottomleySoftware Quality Lead EngineerCommented:
The question is a bit open but if inserting tables for example at the end then the number of tables can be used and incremented i.e. first inserted table is number:

wordobj.ActiveDocument.Tables.count + 1

If necessary something similar can be done for any insertion point if you can give more info on the process

Chris
0
 
Helen FeddemaCommented:
You could select each table in turn, and insert a bookmark for that table, giving it an appropriate name.  Then you could use the bookmark names to go to the desired table.
0
 
Helen FeddemaCommented:
The bookmarks could be created immediately after inserting each table into the document.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Chris BottomleySoftware Quality Lead EngineerCommented:
A bit more flexible is if inserting somewhere in the document then with the cursor in the table you have just inserted use::

application.activedocument.Range(0, selection.Tables(1).Range.End).Tables.Count

Chris
0
 
ewingdjAuthor Commented:
Chris,

I thought about setting up a variable to keep count of the tables as they are inserted into the document and then use this variable as the table index. I was just curious if there was some other means to identify a table other than by its index number.

In my document, certain information stored in one table needs to be added to previous tables, Therefore, I need to be able to reference each table/cell individually since the actual number of inserted tables is data-dependent.
0
 
ewingdjAuthor Commented:
Thanks for the quick response.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now