Using the Stop Statement

Sometimes you won't be able to test your procedure right away. If you set up your breakpoints and then close the file, Excel will remove your breakpoints, and the next time you are ready to test your procedure, you'll have to begin by setting up your breakpoints again. If you need to postpone the task of testing your procedure until later, you can take a different approach. Simply insert a Stop statement into your code wherever you want to halt a procedure. Figure 13-8 shows the Stop statement before the For.. .Next loop. Visual Basic will suspend the execution of the StopExample procedure when it encounters the Stop statement. The screen will display the Code window in break mode. Although the Stop statement has exactly the same effect as setting a breakpoint, it has one disadvantage, all Stop statements stay in the procedure until you remove them. When you no longer need to stop your procedure, you must locate and remove all the Stop statements.

Figure 13-8:

You can insert a Stop statement anywhere in the code of your VBA procedure. The procedure will halt when it gets to the Stop statement,and the Code window will appear with the line highlighted.

0 0

Post a comment