Option Explicit
Sub CreateError1()
Dim x As Workbook
On Error GoTo error:
Set x = Workbooks("dfaksjdfh3u9sdf")
MsgBox "Code Will Continue From Here"
Exit Sub
error:
Call ErrorHandler(Err)
Resume Next
End Sub
Sub CreateError2()
Dim x As Double
On Error GoTo error:
x = 1 / 0
MsgBox "Code Will Continue From Here"
Exit Sub
error:
Call ErrorHandler(Err)
Resume Next
End Sub
Sub ErrorHandler(MyErr As ErrObject)
Dim Prompt As String
Dim Title As String
Dim MyResponse As VbMsgBoxResult
Prompt = "The following error has occured:" & vbNewLine & _
MyErr.Description & vbNewLine & _
"Do you want to terminate this macro?"
Title = "Error"
Select Case MyErr.Number
Case Is = 9
Case Is = 11
End Select
MyResponse = MsgBox(Prompt, vbYesNo, Title)
If MyResponse = vbYes Then
End
End If
On Error GoTo 0
End Sub
|