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
ewingdjAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.