Run mode occurs when a procedure is running. To run (or execute) a procedure, just place the cursor anywhere within the procedure code and hit the F5 key (or select Run from the Run menu). If a running procedure seems to be hanging, you can usually stop the procedure by hitting Ctrl-Break (hold down the Control key and hit the Break key).
Break mode is entered when a running procedure stops because of either an error in the code or a deliberate act on your part (described later in this chapter). In particular, if an error occurs, Word will stop execution and display an error dialog box with an error message, an example of which is shown in Figure 4-2.
Error dialog boxes offer a few options: end the procedure, get help (such as it may be) with the problem, or enter break mode to debug the code. In the latter case, Word will stop execution of the procedure at the offending code and highlight that code in yellow. (I discuss the process of debugging code in the “Debugging” section later in this chapter.)
Hit Ctrl-Break and choose Debug from the resulting dialog box.
Stop statement in the code, which causes Word to enter break mode.
Insert a breakpoint on an existing line of executable code. This is done by placing the cursor on that line and hitting the F9 key (or using the Debug menu). Word will place a red dot in the left margin in front of that line and will stop execution when it reaches the line. You may enter more than one breakpoint in a procedure. This is generally preferred to using the
Stop statement, because breakpoints are automatically removed when you close down the Visual Basic Editor, so you don’t need to remember to remove them, as you do with
Set a watch statement that causes Word to enter break mode if a certain condition becomes true. (I discuss watch expressions later in this chapter.)
To exit from break mode, choose Reset from the Run menu.
Note that the caption in the titlebar of the VBA IDE indicates which mode is currently active. In particular, the caption contains the word “[running]” when in run mode and “[break]” when in break mode.