Microsoft Office 2000 Developer |
In an ideal world, all of the code that you write would run error-free. The reality is that, no matter how carefully you write your code, errors can and will occur. For that reason, it’s a good idea to add error-handling routines to all of your procedures.
The VBA Error Handler add-in makes it easy to add error handlers to your procedures without typing in repetitive code. It inserts standardized error handling templates into your code; you simply fill in any procedure-specific code. You can choose to add error handlers to a single procedure, to all of the procedures within a module, or to all procedures in your project at once.
To add error handlers to your code
Note The VBA Error Handler menu item is only available when the VBA Error Handler add-in is loaded. For more information about loading add-ins, see Accessing Office 2000 Developer Tools.
The VBA Error Handler uses template files (.eht) to control the format of error handling blocks. You can edit the standard template (Errorhandler.eht) or create your own templates using Notepad or another text editor.
To update existing error handlers in your code
When selected, this option updates all existing error handlers within the scope selected in the Add Error Handlers To group so they match the currently selected template.
Note If the Error Handler finds "On Error Goto <label>" within a procedure in existing code, no modifications are made to that code. If the Error Handler finds "On Error Goto <0>" or "On Error Resume Next" within a procedure, the code is modified to match the information specified in the template. The following comment is placed directly before the exiting On Error code:
' TODO: Turn normal error handler on when this condition is finished
For more information about the templates, see Code Commenter and Error Handler Template Formats and Chapter 11, "Add-ins, Templates, Wizards, and Libraries" in the Microsoft Office 2000/Visual Basic Programmer's Guide.