Executing a procedure from the Immediate window

You also can execute a procedure by entering its name in the Immediate window of the VBE. If the Immediate window is not visible, press Ctrl+G. The Immediate window executes VBA statements while you enter them. To execute a procedure, simply enter the name of the procedure in the Immediate window and press Enter.

This method can be quite useful when you're developing a procedure because you can insert commands to display results in the Immediate window. The following procedure demonstrates this technique:

Sub ChangeCase ()

Dim MyString As String MyString = "This is a test" MyString = UCase(MyString) Debug.Print MyString End Sub

Figure 9-5 shows what happens when you enter ChangeCase in the Immediate window: The Debug.Print statement displays the result immediately.

Vriv r^nu:

ftjn TUJI

Qui yy 1 -: LJLi 5TTS : ] XflLL.bg " .( 4 Hit*

Figure 9-5: Executing a procedure by entering its name in the Immediate window.

4 PREV

0 0

Post a comment