On Error GoTo 0
This statement is the Default Error Handler which interrupts execution and displays a dialog box.
If you do not specify which type of error handling you want to use, this is the default.
Public Sub MySubroutine()
On Error GoTo 0
Debug.Print 1 / 0 'generates a "Division by zero" run-time error
'execution stops and a dialog box is displayed
End Sub
Public Sub MySubroutine()
Charts("Chart 1").Activate 'generates a "Subscript out of range" run-time error
'execution stops and a dialog box is displayed
End Sub
Here are the error messages that will be displayed.
Changing the Type Of Error Handling
There are other types of error handling that you can use.
On Error Resume Next
On Error GoTo LineLabel
If you switch to a different type of error handling (Resume Next or GoTo LineLabel) you can switch back to the default by using the "On Error Goto 0" statement.
Resets Automatically
There is no need to include the following line of code at the end of a subroutine (or function).
The type of error handling automatically resets back to the default when the subroutine exits.
On Error GoTo 0
End Sub
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext