On Error GoTo LineLabel
This statement lets you provide a custom error handler.
Public Sub MySubroutine()
On Error GoTo LineLabel
Exit Sub
LineLabel:
Call MsgBox(Err.Number & " - " & Err.Description)
End Sub
The LineLabel must be in the same procedure as the On Error statement.
You should always put this LineLabel at the end of the subroutine.
This section of code between the LineLabel and the End Sub is often referred to as the Error Handling Routine.
You should always include an Exit Sub, Exit Function or Exit Property before your error handling routine to ensure that it is only executed when an error occurs.
On Error GoTo ErrorHandler
You should always use a consistent line label for your error handling.
Public Sub MySubroutine()
On Error GoTo ErrorHandler
Exit Sub
ErrorHandler:
Call MsgBox(Err.Number & " - " & Err.Description)
End Sub
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext