Microsoft Office Tutorials and References
In Depth Information
Testing and Debugging Your Functions
Figure 23-9: The highlighted statement has generated a runtime error.
Using the Immediate window
The VB Editor Immediate window can be helpful when debugging code. To activate the
Immediate window, choose View‚ěúImmediate Window (or press Ctrl+G).
You can type VBA statements in the Immediate window and see the result immediately. For
example, type the following code in the Immediate window and press Enter:
Print Sqr(1156)
The VB Editor prints the result of this square root operation (34). To save a few keystrokes, you
can use a single question mark ( ? ) in place of the Print keyword.
The Immediate window is particularly useful for debugging runtime errors when VBA is in break
mode. For example, you can use the Immediate window to check the current value for variables
or to check the data type of a variable.
Errors often occur because data is of the wrong type. The following statement, for example,
displays the data type of a variable named Counter (which you probably think is an Integer or
Long variable).
? TypeName(Counter)
If you discover that Counter is of a data type other than Integer or Long , you may have
solved your problem.
You can execute multiple statements in the Immediate window if you separate them with a
colon. This line contains three statements:
x=12: y=13 : ? x+y
Search JabSto ::

Custom Search