on error vba code example
Example: vba error handling message
Dim Msg
On Error GoTo errorhandling ' Defer error handling.
' code goes here, where potential problem occours
errorhandling:
' Check for error, then show message.
If Err.Number <> 0 Then
Msg = "Error # " & Str(Err.Number) & " was generated by " _
& Err.Source & Chr(13) & Err.Description
MsgBox Msg, , "Error", Err.Helpfile, Err.HelpContext
Err.Clear
End If