Excel VBA Excel VBA Error Handling & Debugging 2 — Questions and Answers
Question 1: Which VBA debugging action executes code one line at a time, including stepping into called procedures?
- Breakpoints
- Step Into (Correct answer)
- Watch Window
- Immediate Window
Correct answer: Step Into
'Step Into' (F8) executes code one line at a time and enters any called Sub or Function to debug it line by line.
Question 2: What is a breakpoint in the context of VBA debugging?
- A line of code that automatically throws an error
- A marker that pauses execution when that line is reached (Correct answer)
- A special comment that stops code from running
- An error that permanently breaks the code flow
Correct answer: A marker that pauses execution when that line is reached
A breakpoint is a marker set on a specific line that causes VBA to pause execution when reached, allowing inspection of variables and program state.
Question 3: Which window in the VBA IDE allows you to type and execute VBA statements interactively without running a full procedure?
- Watch Window
- Locals Window
- Immediate Window (Correct answer)
- Output Window
Correct answer: Immediate Window
The Immediate Window (Ctrl+G) lets developers type and run VBA expressions instantly, making it ideal for testing snippets and inspecting values.
Question 4: What information does the Locals Window display during VBA debugging?
- All variables declared across the entire project
- All variables in the current procedure scope with their current values and types (Correct answer)
- A list of all VBA error numbers and descriptions
- The complete call stack of procedure invocations
Correct answer: All variables in the current procedure scope with their current values and types
The Locals Window automatically displays all variables in the currently executing procedure's scope, showing their names, types, and current values.
Question 5: Which VBA debugging feature lets you monitor a specific variable or expression and optionally pause execution when its value changes?
- Breakpoints
- Step Over
- Watch Expressions (Correct answer)
- Trace Variables
Correct answer: Watch Expressions
Watch Expressions (added via Debug > Add Watch) monitor specific variables or expressions and can pause execution when the watched value changes or meets a condition.
Question 6: What is the key difference between 'Step Into' (F8) and 'Step Over' (Shift+F8) during VBA debugging?
- Step Into runs all code at once; Step Over runs one line at a time
- Step Into enters called procedures line by line; Step Over executes them as a single step (Correct answer)
- Step Over is faster than Step Into in all scenarios
- Step Into handles errors automatically; Step Over skips them
Correct answer: Step Into enters called procedures line by line; Step Over executes them as a single step
'Step Into' descends into any called Sub or Function to debug it, while 'Step Over' executes the called procedure entirely without entering it.
Question 7: Which VBA statement outputs values and messages to the Immediate Window during code execution for logging purposes?
- Print.Debug
- Debug.Write
- Debug.Print (Correct answer)
- Console.WriteLine
Correct answer: Debug.Print
'Debug.Print' writes values or messages to the Immediate Window at runtime, which is useful for tracing variable values without stopping execution.
Which VBA debugging action executes code one line at a time, including stepping into called procedures?