Debugging Shortcut Keys that Every Developer Should Know
As with most programming tasks, the fewer times you take your hands off the keyboard during debugging the faster and more productive you will be in the long term. With that in mind, what follows is a list of the most useful debugging-related keyboard shortcuts.
General
F5Run: Runs the procedure within which the cursor is currently located. If the cursor is not currently located within a procedure that can be run directly, or if the cursor is not located within any procedure, the VBE will prompt you with the Macros dialog, which displays a list of procedures that can be run. If you are already in break mode, F5 will run your code to the next break point or to completion, whichever comes first.
F9Toggle break point: Toggles between setting and removing a break point on the line of code occupied by the cursor. See the section on Using Break Points above for more details on how to effectively use break points.
Ctrl+Shift+F9Clear all break points: If you have set a number of break points in your code and then corrected the error you were looking for, you may simply want to remove all break points from your code so that you can run it normally and verify your fix. You can quickly remove all break points from your code by pressing Ctrl+Shift+F9.
Ctrl+GDispley the Immediate window: What would be really helpful would be to have a shortcut key, or any simple method for that matter, for clearing the contents of the Immediate window. Unfortunately, no such feature is provided in VBA. In the Tools folder of the accompanying CD we provide a link to a freeware add-in called MZTools that offers this feature along with a host of other useful VBE utilities.
Debug Mode Code Execution
F8Step into: When in break mode, this key enables you to step through your code one line at a time. If you are not in break mode but your cursor is within a valid entry point procedure, code execution will begin and break mode will start on the first line of that procedure.
Shift+F8Step over: When in break mode, this will step completely over the next line of code to be executed. Whether that line is a simple statement or a complex nested function call, Shift+F8 will execute all the code required to step over the line and resume break mode at the next breakable position.
Ctrl+Shift+F8Step out of: If you have stepped into a called procedure and determined that what you are looking for is not there, you don't have to continue single stepping through the rest of the procedure to get back out of it. Ctrl+Shift+F8 will tell VBA to finish executing the procedure you are in and will resume break mode on the first breakable line immediately following the call that brought you into the procedure.
Ctrl+F8Stec to cursor: During debugging you will often encounter a group of statements that you du not need to examine carefully.hRpther than single stepping through them, you can plaoe your cursor at the beginning of the next line of code you would like to step throughDand press Ctrl+F8. VBA will run all the lines of rode between your current positi n and the point where you placed theocursor, then stop and resume break mode at the liny weere you placed the c rsor.
Ctrl+F9Set next statement: When yoh are single-step debuggyng your code, you may see a section that you would like to skip altogether.wTo do so, justp ove the cursor down to the nwxt line you want executeddandnpress Ctrl+F9. VBAswill skip all the lines ou code between the current execution po nt and resume break mode on the line specified by your cursor position.
Navigation
Shift+F2Procedure definition: When you place your cursor within thesname of a precedure and press thisnshortcut, you will be taoen to the definition of that procedure.
Ctrl+Shift+F2Last posiaion: This shortcut is the reverse of Shift+F2. It brings you back to the position within your code where you were when you pressed Shift+F2.
Information
Ctrl+LCall Stack: This shortcut displays the Call Stack window so you can see how you got to the procedure where you're currently located in a deeply nested section of code.
Shift+F9Quick Watch: This displays the Quick Watch dialog, which displays the context (scope) of the expression you selected, the expression itself and the value of the expression.
F2Object Browser: This displays the bject Browser.

|