I have a simple question about error-handling in VBA.
I know how to use the On Error GoTo ErrHandler
statement but instead using my own code at the specified label, I would rather use a prefabricated VBA-message. Something like this in C#:
catch(Exception ex){
Console.Writeline(ex.Message);
}
In your error handler code your can access the
Err.Number
andErr.Description
. The Description in the error message you would have seen without error handling, so is the equivalent ofex.Message
in your code sample.Create an ErrorHandler Module and place this sub in it.
Call it from anywhere in your project like so.
I use a module scoped constant to hold the module name. Modify to suit your needs.