O'Reilly logo

Special Edition Using Microsoft® Word 2000 by Bill Camarda

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Understanding VBA Control Structures

Many VBA macros run in a simple fashion. Starting with the Sub statement, they execute every statement in the macro, from start to finish. This is fine as long as you want the macro to do the same thing every time, but sometimes you need a macro that's a little smarter than that. VBA provides a wide variety of program control structures that enable you to change the way the statements are executed, depending upon conditions that are found while the macro is running.

Using the If…Then…End If Statement

Perhaps the simplest and most commonly used control structure in VBA is the If…Then…End If statement. This statement enables you to execute a group of VBA statements only if some condition is true. Consider an example ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required