Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Understanding the While...Wend Structure.
by Allen Wyatt
(last updated March 31, 2012)
Macros in Word are written in a language called VBA. Like other programming languages, VBA includes certain programming structures that are used to control how the program executes. One of these structures is the While...Wend structure. This structure has the following syntax:
While condition program statements Wend
When a macro is executing and this structure is encountered, the language tests whatever condition you have defined. You can see examples of conditions in many of the macros used in WordTips. If the condition is true, then the program statements between the While and Wend statements are executed. If the condition is not true, execution of the macro continues with the program line following the Wend statement. If the condition is true when Wend is encountered, the macro will loop back up to the While statement and keep executing the loop until the condition becomes false.
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1886) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Understanding the While...Wend Structure.
Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!
One way you can access macros is through the use of a button, added directly into the text of your document. This is done ...Discover More
Need to create a directory from within a macro? You can do it using a single command line, as detailed in this tip.Discover More
You may have a need to find out how many times a certain text string occurs within a document. You can find out manually ...Discover More
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.