Computer Forum Forum Index
Register  FAQ Profile Log in to check your private messages Log in Register 

Identify a Table

 
Post new topic   Reply to topic    Computer Forum Forum Index -> word vba customization
View previous topic :: View next topic  
Author Message
Sridhar
Guest





PostPosted: Mon Dec 10, 2007 2:42 am    Post subject: Identify a Table Reply with quote

Is there any way to Identify a particular table from the list of available
tables in the word page.

I have a Single Page Word document which has 8 tables inserted from
different files. Now i need to fill a particular table with values.
When i used Thisdocument.Tables (Number) Sometimes i am getting the right
table and some times not the right one.
How can i fill data to the right table.

Thanks
Sri
Back to top
Google
Sponsor





PostPosted: Mon Dec 10, 2007 2:42 am    Post subject: Advertisement

Back to top
Tony Strazzeri
Guest





PostPosted: Mon Dec 24, 2007 5:39 am    Post subject: Re: Identify a Table Reply with quote

You could try setting the Table.ID property on each of the tables and
then check if against the table you have. Unfortunately I don't thnk
there is anyway to specifically select a table by its ID. You would
need to iterate each table in the document and until you found the one
with the correct ID. You need to be aware however that the ID is not
unique.

Have a play with the code below to see what I mean. Run it first on a
blank document then again (leaving the tables that were created the
first time).

Hope this helps.

Cheers
TonyS.


Dim tbl As Table
Dim MyTable As Table

Selection.EndKey Unit:=wdStory
Selection.TypeParagraph
Selection.TypeParagraph
Set tbl = ActiveDocument.Tables.Add(Range:=Selection.Range,
NumRows:=2, NumColumns:=5)
tbl.ID = "MyFirstTable"

Selection.EndKey Unit:=wdStory
Selection.TypeParagraph
Selection.TypeParagraph
Set tbl = ActiveDocument.Tables.Add(Range:=Selection.Range,
NumRows:=2, NumColumns:=5)
tbl.ID = "MySecondTable"


Selection.EndKey Unit:=wdStory
Selection.TypeParagraph
Selection.TypeParagraph
Set tbl = ActiveDocument.Tables.Add(Range:=Selection.Range,
NumRows:=2, NumColumns:=5)
tbl.ID = "MyThirdTable"

Selection.EndKey Unit:=wdStory

For Each tbl In ActiveDocument.Tables
If tbl.ID = "MySecondTable" Then
Set MyTable = tbl
Exit For
End If
Next

MyTable.Select
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Computer Forum Forum Index -> word vba customization All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Computer Forum