WD: WordBasic Macro to Find Tables in a Word Document

Last reviewed: February 2, 1998
Article ID: 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
  • 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 "t" identifier is used to specify a table. The following statement moves the insertion point to the first cell in the next table.

 EditGoTo "t+"   '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("\sel", "\endofdoc") 'While loop
 n = SelInfo(12)              'Returns -1 if in table
 If n = - 1 Then              'If -1 is returned post message
  choice = MsgBox("Table found, find next table?", 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 "Table Found." 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 "as is" 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.

REFERENCES

"Using WordBasic," by WexTech Systems and Microsoft, pages 277-278, 333

Kbcategory: kbusage kbmacro KBSubcategory: kbtable


Additional query words: winword2 word6 7.0 word95 word7 6.0.1
macword winword 2.0 2.0a
Keywords : kbtable macword ntword winword winword2 word6 word7 kbmacro
Version : WINDOWS:2.0,2.0a,2.0a-CD,2.0b,2.0c,6.0,6.0a,6.0c,7.0,7.0a; MACINTOSH:6.0,6.0.1,6.0.6.0.1a


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 2, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.