The debugger's Immediate Window is a powerful tool, ranking right up there with those electric bug zappers sold at a good hardware store. Since the Immediate Window is interactive it can do things the Object Browser and Help can't, like viewing variables and giving instant feedback on syntax. To troubleshoot an error set a breakpoint in the code just before the problem and then try printing key variables. If an object reference is confusing just type it in on the fly and see what happens. Chances are that typing a few combinations of references into the immediate window will hit on the correct one or at least produce valuable clues about what's wrong. To print a variable or expression, just place a question-mark character in front of it. There's no need to type in similar keystrokes several times; just use the scrollbar to bring the lines into view. Modify the line or cut and paste the line to duplicate it. Think of the Immediate window as a fast, interactive way to try out object references to see if they're right.
Type in the object reference here, then watch the result.
Figure 10. Using the Immediate Window to resolve a tricky object reference.
Here's another tip. Code can activate objects in the Immediate Window. The activation shows up on the screen right away. When debugging there are times when it's important to see another part of the workbook, but the debugger prevents you from clicking on the worksheet tabs. Instead, just type in the command to activate the worksheet in the Immediate Window, as in Figure 11 below. To scroll a window, use the LargeScroll method. The following statement
ActiveWindow.LargeScroll down:=1
will scroll the active window down a page. To scroll in any direction use the up, down, toRight, and toLeft parameters. In Excel 7 there's less of a need to do this manually as most window operations can be performed with the mouse while the debug window is open.
Figure 11. Activating a worksheet from the Immediate Window.