Besides the two methods you mentioned (of which the bookmark is more
reliable), here are three more:
(1) If the cursor is in the table (that is, you're assuming the user
will choose the table before starting the macro), then it's
Selection.Tables(1). That refers to the "first table of which any part
is in the Selection" regardless of the table's index in the total
document.
(2) If you're applying the same actions to all the tables in the
document, you can use the For Each construct:
Dim oTbl As Table
For Each oTbl In ActiveDocument.Tables
' do something with oTbl
Next
(3) Use the .Find method of a Range object to search for some text
that may be in the table, and verify that it's in a table before doing
some work:
Dim oRg As Range
Dim oTbl As Table
Set oRg = ActiveDocument.Range
With oRg.Find
.ClearFormatting
.Text = "look for this"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = False
Do While .Execute
If oRg.Information(wdWithInTable) Then
Set oTbl = oRg.Tables(1)
' do something with oTbl
End If
Loop
End With
There are probably others, but that covers the most common ones.
--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.