Previous Chapter - [Debugging in VBA - 1) Overview]
Next Chapter - [Debugging in VBA - 2B) The Project Explorer Pane (Ctrl-R)]
-----------------------------------------------------------------------------------------------
2A) The Code Pane (F7).
This is the main pane and doesn't have a title.
From here you can do all sorts of things with the code, including editing it.
As mentioned earlier, the code can be developed (written) into the Code Pane. This is possibly the least exciting use for this pane however.
In here you can :
- Go to various sections of the code quickly and easily.
You can open the code for various modules (See Project Explorer pane). You can also select a procedure from the Object Selection box (Top-Left) in conjunction with the Event Selection box (Top-Right). - Pause the execution of the code (as it's running).
This can be done manually (Ctrl-Break); by a breakpoint; by an error; or coming to the end of the code. When stopped (as opposed to finished) this is called Break Mode. - See the current contents of simple variables.
(See attached picture - the lighter yellow area.) This shows up when you hover the mouse cursor over the name of a variable in the code. - Set & Clear Breakpoints.
(See attached picture - the lines with the reddish background are breakpointed.) This means that when the code execution hits this line it will stop. Setting and clearing breakpoints is as simple as clicking in the margin where the redddish spot appears. - Resume execution from the current position in the code.
(See attached picture - the line in yellow is the current position.)
Options available :- F5 - Resumes execution. Doesn't stop unless stopped (See paragraph b above).
- F8 - Execute single instruction (Step Into). Stops at the very next instruction. Including the first instruction of a sub-procedure if the current line includes one.
- Shift-F8 - Stops when it hits the following line in the code (Step Over).
Doesn't stop within a sub-procedure even if the current line includes one. - Ctrl-Shift-F8 - Resume until the current procedure is complete (Step Out).
- Ctrl-F8 - Resume until the code hits the line the cursor is on (Run to Cursor).
- Resume execution from your chosen position in the code.
Right-click on your chosen line and select 'Set Next Statement'. This allows particular lines to be skipped where necessary, or even a line to be retried after changes have been made.