ON ERROR GOTO Label
The program goes to the point in the code with the label and continues executing (presumably, you have defined what to do here to mitigate the error)ON ERROR RESUME NEXT
The program will continue ignoring errors until it either can't run at all, you handle the errors, or you disable the resume next option. I often (but not always) use ON ERROR RESUME NEXT to allow the program to continue and then I explicitly check for an error number and handle the error there. For example:ON ERROR RESUME NEXT
X = 5
IF X = "bob" THEN X = "Bob"
IF ERR.NUMBER <> 0 THEN
'Handle the error
END IF
ON ERROR GOTO 0
Do more with
Private Sub CatchErrors()
Dim strWhere As String
strWhere = "A"
On Error GoTo ErrorRoutine
' some code where On Error Resume Next is appropriate
strWhere = "B"
On Error GoTo 0
Exit Sub
ErrorRoutine:
Select Case strWhere
Case "A"
MsgBox "Error at " & strWhere
Case "B"
MsgBox "Graceful error at " & strWhere
Resume Next
End Select
End Sub
Premium Content
You need an Expert Office subscription to comment.Start Free Trial