bottom
Great WordTips!
         
Your e-mail address is safe!
Close Note

Tips.Net > WordTips Home > Macros > Creating Macros > Repeating in a WordBasic Macro

Repeating in a WordBasic Macro

Summary: How to loop through a complete document in your WordBasic macro. (This tip works with Microsoft Word 6, and Word 95.)

One of the most common things you need to do when creating a macro is to repeat a block of actions for each occurrence of something within a file. This may sound strange, but those who program know the situation very well--you need to search through a file and then take some action, repeat the search and repeat the action, and so on until the end of the file is reached.

If you are using WordBasic (Word 6 or Word 95), the general approach is as follows:

StartOfDocument
[search for something]
While EditFindFound()
    [take some action]
    [repeat the search]
Wend

The first line moves the insertion point to the beginning of the document, where you can begin your search. After the search you use a While ... Wend loop with the EditFindFound() function. This function returns a True value if the last search was positive, or False if nothing was found. Once inside the While ... Wend loop you can then take any action desired. As the last step within the While ... Wend loop, simply repeat your search and the loop will run until Word can no longer find what you are looking for.

Tip #1084 applies to Microsoft Word versions: 6 | 95


Take Control! Master the real power behind Word! Successfully master the secrets of powerful formatting and create documents that stand out from the rest. Best of all, you can create documents that are easy to maintain and quick to change.
 
Check out WordTips: Sytles and Templates today!

Helpful Links

Ask a Word Question
Make a Comment

Tips.Net Home
Vital News Home

WordTips FAQ
WordTips Premium

Learn Access Now

Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips

Advertise on the
WordTips Site

 

Great Info!

Get tips like this every week in WordTips, a free productivity newsletter. Enter your e-mail address and click "Subscribe."
     
(Your e-mail address will never be shared with anyone, ever.)