Page 61 - Microsoft Office Excel 2003 Programming Inside Out
P. 61

Exploring Visual Basic for Applications

                             Table 3-2.  Keyboard Shortcuts for Executing Macro Steps in the Visual
                             Basic  Editor

                             Sequence          Result
                             F5                Runs the macro code.
                             F8	               Executes the highlighted step in the macro code and moves the high-
                                               light to the next step in the code.
                             Shift+F8	         Skips the highlighted step and moves the highlight to the next step in
                                               the code.
                             Ctrl+Shift+F8     Stops executing the macro code.
                             Ctrl+F8	          Positions the cursor in the macro code; pressing Ctrl+F8 causes the
                                               editor to run the code until it reaches the cursor.
                             Shift+F9	         Sets a quick watch to follow the value of a selected variable in the
                                               code.
                             F9	               Inserts a breakpoint at the cursor, which will allow the code to exe­
                                               cute to that point but then stop.
                                                                                                             Chapter 3
                             Ctrl+Shift+F9     Clears all breakpoints.
                             Ctrl+F9           Identifies the selected statement as the next statement to execute.

                             When your macro runs but doesn’t produce the result you’re expecting, it makes the most
                             sense to have your macro code in one window and your worksheet in another, and to step
                             through the macro one line at a time using F8. Skipping steps with Shift+F8 lets you bypass
                             any instructions that you know aren’t operating correctly, and if things aren’t going right at
                             all and you want to stop before anyone gets hurt, Ctrl+Shift+F8 lets you stop the whole pro€
                             cess. You don’t undo any of the steps that occurred before you pressed Ctrl+Shift+F8, but you
                             do prevent any additional code from running.


                             Caution  When you’re running and re-running a macro, don’t forget to undo the changes
                             the macro made to your worksheet. If you don’t, you won’t see any changes the next time
                             you run it.

                             A breakpoint, by contrast, is a set stopping point that lets you run the code up to the break-
                             point. You can continue past the breakpoint by pressing F5. As shown in Figure 3-5, the
                             Visual Basic Editor indicates the presence of a breakpoint by putting a dot in the vertical bar
                             at the left edge of the code window, and displaying the code in reverse video.













                                                                                                        35
                                                                                        Part 2:  Visual Basic for Applications
   56   57   58   59   60   61   62   63   64   65   66