Info

Sometimes the VBA window seems to not respond to hovering. Because some expressions are not supposed to show a value, it is difficult to tell whether VBA is not displaying the value on purpose or whether you are in the buggy "not responding" mode. Try hovering over something that you know should respond (such as a variable). If you get no response, then hover, actually click into the variable, and continue to hover. This tends to wake Excel up from the stupor and hovering will work again.

Are you impressed yet? I started the chapter complaining that this didn't seem much like BASIC, but you have to admit that the Visual Basic environment is great to work in. These debugging tools are excellent.

Querying by Using a Watch Window

In Visual Basic, a Watch is not something you wear on your wrist. It allows you to watch the value of any expression while you step through code. Let's say that in the current example, I wanted to watch to see what is selected as the code runs. I would set up a Watch for Selection.Address.

From the VBE menu, select Debug, Add Watch.

In the Add Watch dialog, enter Selection.Address in the Expression text box and click OK (see Figure 2.34).

Figure 2.34

Setting up a Watch to see the address of the current selection.

Figure 2.34

Setting up a Watch to see the address of the current selection.

A Watches window is added to the busy Visual Basic window. It is usually added at the bottom of the Code pane. I started running the macro, importing the file and pressing End+Down to move to the last row with data. Right before the Range("Al4").Select code is executed, the Watches window shows me that Selection.Address is $A$10 (see Figure 2.35).

Figure 2.35

Without having to hover or type in the Immediate window,you can always see the value of watched expressions.

Press the F8 key to run the code Range("Al4").Select. The Watches window is updated to show the current address of the Selection is now $A$14 (see Figure 2.36).

Figure 2.36

The Watches pane appears at the bottom of the Code pane.Without having to hover or type in the Immediate window, you can always see the value of watched expressions. Here, you see that just before selecting cell A14, the value of Selection.Addres s is $A$10.

0 0

Post a comment