Stopping a Procedure

VBA offers four methods of stopping your procedure and entering into a so-called break mode:

■ Pressing Ctrl+Break

■ Setting one or more breakpoints

■ Inserting the Stop statement

■ Adding a watch expression

A break occurs when execution of your VBA procedure is temporarily suspended. Visual Basic remembers the values of all variables and the statement

Part I

from which the execution of the procedure should resume when you decide to continue. You can resume a suspended procedure in one of the following ways: ■ Click the Run Sub/UserForm button on the toolbar Choose Run | Run Sub/UserForm from the menu bar Click the Continue button in the dialog box (see Figure 9-2)

Figure 9-2: This message appears when you press Ctrl + Break while your VBA procedure is running.

Figure 9-2: This message appears when you press Ctrl + Break while your VBA procedure is running.

The error dialog box shown in Figure 9-2 informs you that the procedure was halted. The following buttons are available:

Table 9-1: Error dialog buttons

Button Name

Description

Continue

Click this button to resume code execution. This button will be grayed out if an error was encountered.

End

Click this button if you do not want to troubleshoot the procedure at this time. VBA will stop code execution.

Debug

Click this button to enter break mode. The Code window will appear, and VBA will highlight the line at which the procedure execution was suspended. You can examine, debug, or step through the code.

Help

Click this button to view the online help that explains the cause of this error message.

0 0

Post a comment