Table of Contents

Error Handling

typical example

Private Sub someSub()
On Error Goto HandleError
 
  ' Attempt something here, possibly
  ' generating an error
 
ExitSub:
  ' Do cleanup here
  Exit Sub
 
HandleError:
  ' Do something about the error
  Goto ExitSub
End Sub

ignore errors and keep going

Private Sub someSub()
On Error Resume Next
 
  ' Attempt something here, possibly
  ' generating an error
End Sub

alternate HandleError

HandleError:
Debug.Print "Error: " & _ ' the underscore (_) allows code to continue on the next line
Err.Description & ",(" & Err.Number & ")"
Resume Next

Resume options