docs:programming:office_vba:error_handling

Error Handling

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
Private Sub someSub()
On Error Resume Next
 
  ' Attempt something here, possibly
  ' generating an error
End Sub
HandleError:
Debug.Print "Error: " & _ ' the underscore (_) allows code to continue on the next line
Err.Description & ",(" & Err.Number & ")"
Resume Next
  • Resume
    • this will pick up with the same line causing the error, as if to keep trying
  • Resume Next
    • resume normal program functionality at the line after the one causing the error
  • Resume <line>
    • where <line> is the line number to jump to
  • docs/programming/office_vba/error_handling.txt
  • Last modified: 2008/08/03 00:25
  • by 127.0.0.1