
Tips.Net > WordTips Home > Macros > WordBasic Examples > Moving Through a Table in a WordBasic Macro
Summary: Do you need your WordBasic macro to step through the contents of a table? Use this technique. (This tip works with Microsoft Word 6, and Word 95.)
There may be times when you want to move the insertion point from cell to cell in a table. (Under the control of your macro, of course). If you are developing a WordBasic macro, this is done with the NextCell and PrevCell statements, as shown here:
Selection.Move Unit:=wdCell, Count:=1
In this case, the insertion point moves forward by one cell. If you want to instead move backward, just change the value used for Count:
Selection.Move Unit:=wdCell, Count:=-1
As you might expect, NextCell moves to the next cell, and PrevCell moves to the previous. The insertion point moves to the beginning of the next or previous cell. When moving forward, the insertion point moves left to right, top to bottom through a table. If moving backward, the movement is from right to left, bottom to top.
When the beginning of the table is reached using PrevCell, the command has no further effect. When the end of the table is reached using NextCell, then Word adds a new row to the table and starts across again. If your WordBasic macro is left uncontrolled, NextCell could keep adding rows to your table until the cows come home. If you know how many cells are in the table, however, it can be very useful in inserting or checking information contained therein.
Tip #800 applies to Microsoft Word versions: 6 95
Step Up and Take Control! Subscribers to WordTips know just how valuable a resource it is. WordTips Premium provides twice the number of exceptional, easy-to-understand tips every week in an ad-free newsletter, as well as substantial discounts on WordTips archives and e-books.
Check out WordTips Premium today!
Add power to your purpose with Word. A comprehensive 480+ page e-book explains everything you need to know about macros. (more information...)
Ask a Word Question
Make a Comment
Bugs and Pests Tips
ExcelTips
Family Tips
Health Tips
Home Tips
Organizing Tips
WordTips