Microsoft Office 2000/Visual Basic Programmer's Guide |
The VBA run-time debugging tools are designed to give you a snapshot of what is happening in your code at any point. You use these tools together to let you take a closer look at what your code is doing at any point in time. The following table contains a list of all the tools available to you and a short description of when they are useful.
Tool | Description |
Breakpoints | Breakpoints let you stop program execution on any line of executable code. Once execution has stopped, you can use one or more of the other available tools to investigate your code. A breakpoint will stop your code on the line of code that will be executed next. Once your code encounters a breakpoint, it is in break mode and remains in break mode until you press F5 to continue execution. |
Step modes | You can use the four step modes to start execution of a subroutine or to continue execution after it has stopped at a breakpoint. The four available modes are Step Into, Step Over, Step Out, and Run To Cursor. Using any of these modes to step through code does not take the code out of break mode. |
Locals window | This extremely powerful and often overlooked tool provides a snapshot view of the values of all variables, constants, objects, and properties of objects currently in scope when code is in break mode. |
Watch expressions | Watch expressions let you monitor the value of any variable, property, object, or expression as your code executes. They also let you specify that your code should enter break mode upon some condition; for example, if an expression is true or if the value of a variable changes. If you don't need to continually monitor a value, you can use the Quick Watch dialog box to quickly check the value of a variable or expression. |
Immediate window | This window is an extremely versatile tool that you should be using constantly to debug and test your code. All Debug.Print statements are output to the Immediate window. When your code is in break mode, the Immediate window has the same scope as the procedure in which the breakpoint is located. This allows you to test and change the value of variables. You can also use the Immediate window to call procedures and test them by using different data without having to run your application from the beginning. |
Call stack | This stack contains a list of all active procedures when code is in break mode. This list can help you trace the execution of your code and highlight the possible location of errors in currently active procedures. |
For more information about any of the debugging tools, search the Visual Basic for Applications Reference Help index for the name of the specific tool.