ewingdj
asked on
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.InsertFi le 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.Tab les(9).Cel l(x,y).Sel ect
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
wordobj.Selection.InsertFi
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.Tab
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
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.
The bookmarks could be created immediately after inserting each table into the document.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
ASKER
Thanks for the quick response.
wordobj.ActiveDocument.Tab
If necessary something similar can be done for any insertion point if you can give more info on the process
Chris