The Immediate Window
The Immediate window (see Figure 3-8) has two main functions. First, we can send output to this window using the command:
Debug.Print
For instance, the code:
Debug.Print ActiveWindow.Selection.Range.Text
will print whatever text is currently selected in the active window to the Immediate window. For instance, Figure 3-8 shows what happened when I selected the words “whatever text is currently selected” in the previous sentence and then ran the procedure shown in the Code window of Figure 3-8. We can see the result in the Immediate window. This provides a nice way to experiment with different code snippets.

Figure 3-8. The Immediate window
The other main function of the Immediate window is to execute commands. For instance, by selecting some text in the active document, switching to the Immediate window, and entering the line shown in Figure 3-9, the selected text will be boldfaced (after pressing the Enter key to execute the code).

Figure 3-9. The Immediate window: command execution
The Immediate window is an extremely valuable tool for debugging (finding errors in) a program, and you will probably use it often (as I do).
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access