When handling errors within VBA code, there are a few methods commonly utilized. One of these methods is to use in-line error handling with On Error Resume Next
. However, I found it unclear after reading the existing question "VBA: How long does On Error Resume Next work?" if the program continued execute on the very next line or if the program would continue executing at the next logical point.
MSDN has the following description for the functionality of On Error Resume Next
:
Specifies that when a run-time error occurs, control goes to the statement immediately following the statement where the error occurred where execution continues. Use this form rather than On Error GoTo when accessing objects.
Additionally, there was (now retired) StackOverflow Documentation on the Resume
keyword which states something similar for On Error Resume Next
:
Resume Next
continues execution on the statement immediately following the statement that caused the error. If the error isn't actually handled before doing that, then execution is permitted to continue with potentially invalid data, which may result in logical errors and unexpected behavior.
This does not clearly state how the error handling line handles errors in the initial line of control flow statements. Specifically, if the error occurs in the first line of an If .. Then .. Else .. End If
statement, will the program run starting on the first line inside the If
statement or will the program run starting on the first line after the End If
statement?