Microsoft KB Archive/88540

{|
 * width="100%"|

WD: WordBasic Macro to Find Tables in a Word Document

 * }

Q88540

-

The information in this article applies to:


 * Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
 * Microsoft Word for Windows 95, version 7.0
 * Microsoft Word for the Macintosh, versions 6.0, 6.0.1

-

SUMMARY
You can use the EditGoto statement in Word to move to the next table in your document. The &quot;t&quot; identifier is used to specify a table. The following statement moves the insertion point to the first cell in the next table.

 EditGoTo &quot;t+&quot;  'moves to the next table

You can use the EditFind command to search for a number of special characters. However, this command cannot be used to locate a table in a Word for Windows document. To search for tables in a document, use the following macro:

Sub MAIN StartOfDocument While CmpBookmarks(&quot;\sel&quot;, &quot;\endofdoc&quot;) 'While loop n = SelInfo(12)             'Returns -1 if in table If n = - 1 Then             'If -1 is returned post message choice = MsgBox(&quot;Table found, find next table?&quot;, 4) If choice = 0 Then Goto bye If choice = - 1 Then       'If OK pressed, find next. TableSelectTable CharRight 1 EndIf Else LineDown 'If no table found, line down 1 End If Wend bye: End Sub

MORE INFORMATION
The above macro uses a While Wend loop to search through the document for tables. The macro uses the SelInfo command to determine if the cursor is in a Word for Windows table. SelInfo(12) will return a -1 if the selection is in a Word table, and Word displays a message box with the text &quot;Table Found.&quot; If the selection does not contain a table, the macro will move the cursor to the next line in the document.

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code &quot;as is&quot; without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.