Word.Tips.Net Welcome toWord.Tips.Net

Helpful Links

Tips.Net Home
WordTips Home

Ask a Word Question
Make a Comment

Tips.Net Store

WordTips FAQ
WordTips Premium

Learn Access Now
Free Printable Forms

Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Legal Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Wedding Tips
Word2007 Tips
WordTips

Advertise on the
WordTips Site

Newest Tips

Setting Fraction Bar Overhang Spacing in the Equation Editor

Printing On Both Sides of the Paper

Turning Off AutoComplete for Dates

Ordering Search and Replace

Understanding Auto Line Spacing

Adding Comments to Your Document

Conditional Calculations in Word

 

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

Save Time! WordTips has been published weekly since early 1997. Past issues are available in convenient WordTips archives. Have your own enhanced archive of WordTips at your fingertips, available to use at any time!
 
Check out WordTips Archives today!