There are some tables in my document, and the cusor focus in somewhere.
How can I get the object of next table, like this statement:
Set oTab = Selection.Tables(1).Next 'this is pseudocode
The pseudocode is nice, but the Table object doesn't have a Next
method. Try this instead:
Function NextTable() As Table
Dim oTab As Table
Dim nIndex As Long
Set oTab = Nothing ' not really necessary
If Selection.Information(wdWithInTable) Then
' get index of table containing selection
nIndex = ActiveDocument.Range(0, _
Selection.Tables(1).Range.End).Tables.Count
' get the next table (if any)
If nIndex < ActiveDocument.Tables.Count Then
Set oTab = ActiveDocument.Tables(nIndex + 1)
End If
End If
Set NextTable = oTab
Set oTab = Nothing
End Function
Sub test()
Dim myTab As Table
Set myTab = NextTable()
If Not (myTab Is Nothing) Then
MsgBox myTab.Cell(1, 1).Range.Text
myTab.Cell(1, 1).Range.Select
Selection.Collapse wdCollapseStart
End If
End Sub
The technique for getting the absolute index of the selected table is
from this article:
http://word.mvps.org/FAQs/MacrosVBA/GetIndexNoOfPara.htm