“I have not failed. I have just found ten thousand ways that won’t work.” [Thomas Edison]

Abstract

Your Excel VBA code does not necessarily need to stop when your program detects an error. You can trap errors with

On Error GoTo <Label>

or you can ignore them with

On Error Resume Next

Please see (external link!) Chip Pearson’s page on Error Handling for an introduction.

A more advanced example on how to apply error trapping is given in my UDF sbMiniPivot.

A note of caution: Make sure your VBA is set to “Break on Unhandled Errors”!

Break_on_Unhandled_Errors

If “Break on All Errors” is selected, your VBA error trapping code “On Error …” will simply be ignored. If an error occurs Excel will come up with an error message.

“Break in Class Module” is a reasonable option if you need to debug classes. Excel will normally not highlight an error in a class module but come back with an error message on the calling code which invoked it. Set this option to let Excel show the error in the class module.

Unfortunately Excel lacks a feature like Application.GetOption(“Error Trapping”) which MS Access is offering. Mark Lundberg came up with the nifty code

Application.SendKeys "%{F11}%TO+{TAB}{RIGHT 2}%E~%{F4}"

but I suggest to stick to manual (human) awareness.