PDA

View Full Version : Solved: Table ID



MWE
02-18-2006, 11:48 AM
I am running Word2000 and Win/XP. I wish to uniquely identify vba-created tables in a word doc. I could not find anything so obvious as Table.Name, but I did find Table.ID But this property does not seem to be persistent.

During the table creation process, I assign an ID and then display Table.ID to the screen when the creation of that table is finished. Everything seems fine.

But if I then run a proc that indexes through all tables in the document and displays Table(I).ID, the # of tables is correct, but all the IDs have been wiped out.

What's going on here? http://vbaexpress.com/forum/images/smilies/102.gif

Thanks

TonyJollans
02-18-2006, 04:33 PM
Tables in Documents do not have any unique form of identification.

Table IDs are for use when saving documents as web pages - where an ID can be meaningful, and referenced in, say, Style sheets or Javascript.

MWE
02-19-2006, 08:11 AM
Tables in Documents do not have any unique form of identification.

Table IDs are for use when saving documents as web pages - where an ID can be meaningful, and referenced in, say, Style sheets or Javascript.
Thanks for the reply. Seems strange that tables would not have a "name", but ...

I need to find some way to reference an existing table at some future point (could be 10 seconds after creation or 10 days). I suspect the simpliest thing to do is to use the table's "Title", i.e., what is found in Row(1). That will be unique. I can loop through all the tables in the document and check Table(I).Row(1). I could also bookmark each table with its "ID" used for the bookmark name and loop through the bookmarks looking for the appropriate name.

Any other thoughts?

Thanks

mdmackillop
02-19-2006, 10:06 AM
You could create a bookmark for the table when you create it, and use this to go retrieve the table index number for manipulation.
http://word.mvps.org/FAQs/MacrosVBA/GetIndexNoOfPara.htm



'Create table with bookmark
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:= 5
Selection.Tables(1).Select
ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:="T1"
'Retrieve bookmark table index
ActiveDocument.Bookmarks("T1").Select
Selection.Collapse wdCollapseStart
tmp = ActiveDocument.Range(0, Selection.Tables(1).Range.End).Tables.Count

MWE
02-19-2006, 05:03 PM
You could create a bookmark for the table when you create it, and use this to go retrieve the table index number for manipulation.
http://word.mvps.org/FAQs/MacrosVBA/GetIndexNoOfPara.htm



'Create table with bookmark
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:= 5
Selection.Tables(1).Select
ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:="T1"
'Retrieve bookmark table index
ActiveDocument.Bookmarks("T1").Select
Selection.Collapse wdCollapseStart
tmp = ActiveDocument.Range(0, Selection.Tables(1).Range.End).Tables.Count

Thanks for the reply. I had already bookmarked the target table as part of the creation process, so perhaps my thread was not necessary.