Dealing with Unanticipated Errors

No matter how carefully you plan, you cannot always anticipate every specific error that may crop up in a procedure. For this reason, it's a good idea to include generic error-handling code in all procedures, in addition to code to handle specific anticipated errors. By definition, an unanticipated error is not one you can handle in a specific manner, but you can at least provide a display of information about the error (and write it to a log file if one is being used).

When dealing with unanticipated errors, it is very useful to know exactly where the error occurred—in other words, in which procedure. There is no way for VBA to provide this information automatically, but you can do it yourself fairly easily. ...

Get Office® XP Development with VBA now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.