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

Tips.Net > WordTips Home > Macros > WordBasic Examples > Understanding the If ... End If Structure

Understanding the If ... End If Structure

Summary: The VBA programming language includes several programming structures that can modify the way in which programming statements are executed. This tip explains one of those structures and how it allows you to place conditions on when certain parts of your macro are executed. (This tip works with Microsoft Word 97, Word 2000, Word 2002, and Word 2003.)

Macros in Word are written in a language called Visual Basic for Applications (VBA). Like any other programming language, VBA include certain programming structures used to control how the program executes. One of these structures is the If ... End If structure. The most common use of this structure has the following syntax:

If condition Then
    program statements
Else
    program statements
End If

When a macro is executing, and this structure is encountered, Word tests whatever condition you have specified following the If keyword. If the condition is true, then the program statements right after the Then keyword are executed. If they are not true, then the statements after the Else keyword are executed. The Else keyword and any following program statements (which together make up an Else clause) are optional; you do not need to include them in your macro.

Regardless of whether the program statements in the If ... End If structure are executed, when Word is done with the structure, the macro continues running with the statement following the End If keyword.

Tip #125 applies to Microsoft Word versions: 97 | 2000 | 2002 | 2003


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
Tips.Net Store

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.)