Microsoft Office Tutorials and References
In Depth Information
Figure 24-9: The highlighted statement generated a runtime error.
When you click the Debug button, the procedure is still running — it's just halted and is
in break mode. After you make the correction, press F5 to continue execution, press F8
to continue execution on a line-by-line basis, or click the Reset button (on the Standard
toolbar) to halt execution.
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 fol-
lowing 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 ex-
ample, 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).
Search JabSto ::




Custom Search