Skip to content

VBA Error Handling

Examples

Example 1

On Error Resume Next
    ' This might have side effects like uninitialized 
    ' variables or null objects

If Err.Number <> 0 Then  
    ' This checks whether there is an error:
    ' If it is not equal to zero that means 
    ' there is some exception in the code

Example 2

On Error GoTo ErrHandler

Exit Sub  'to exit the Sub in case of no error
ErrHandler: