On Error GoTo LineLabel

This statement lets you provide a custom error handler.

Public Sub MySubroutine() 
   On Error GoTo ErrorHandler


   Exit Sub
ErrorHandler:
   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.


Nested Subroutines




© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext