Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2005

Tip: Looking for answers? Try searching our database.

How to get the "next table" and the "previous table"

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
animator - 07 Jan 2005 02:13 GMT
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
Jay Freedman - 07 Jan 2005 04:53 GMT
>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

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.