Microsoft Office Tutorials and References
In Depth Information
Watches and Scope
To be available for a watch, a variable must currently be in scope. If you are debugging code in
one procedure, the local variables in a second procedure will not be available because they are
out of scope. Out of scope variables in a watch expression display as Out Of Context until the
variable comes back into scope.
The Locals Window
VBA provides yet another useful way of keeping track of the values of program variables — the
Locals window. To display this window, shown in Figure 22.12, select Locals Window from the
View menu. You cannot specify what is shown in this window — it always displays the values and
types of all variables, properties, objects, and constants that are in scope at the time the program
enters break mode.
The Locals window.
Controlling Macro Execution
The ability to control the execution of your macro can be an essential part of debugging. Earlier
in this section you have seen how to pause macro execution, entering break mode based on code
location or on the value of program variables. Once you are finished working in break mode, you
have several choices on the Debug menu:
n Continue (F5): Continues macro execution normally.
n Step Into (F8): Executes the next statement then pauses in break mode. If the next
statement is a procedure call, pauses at the first statement in the procedure.