Setting the Next Statement

At times, you may want to rerun previous lines of code in the procedure or skip over a section of code that is causing trouble. In each of these situations, you can use the Set the Next Statement option on the Debug menu. When you halt execution of a procedure, you can resume the procedure from any statement you want. Visual Basic will skip execution of the statements between the selected statement and the statement where execution was suspended. Suppose that in MyProcedure (see the code of this procedure in the preceding section) you have set a breakpoint on the statement calling the SpecialMsg procedure. To skip the execution of the SpecialMsg procedure, you can place the insertion point inside the statement Work-books(myName).Close and press Ctrl+F9 (or choose Debug | Set Next Statement). You can't use the Set Next Statement option unless you have suspended the execution of the procedure.

Tip 13-4: Skipping Lines of Code

Although skipping lines of code can be very useful in the process of debugging your VBA procedures, it should be done with care. When you use the Next Statement option, you tell Visual Basic that this is the line you want to execute next. All lines in between are ignored. This means that certain things that you may have expected to occur don't happen, which can lead to unexpected errors.

0 0

Post a comment