O'Reilly logo

Writing Word Macros, Second Edition by Steven Roman PhD

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

The Immediate window

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).

The Immediate window: command execution

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).

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required