Show Contents / Index / Search

Error-Handling Routines

After you set an error trap, write the error-handling routine that will deal with errors that are likely to occur — in addition to unanticipated errors — when your macro runs. You can identify an error-handling routine by its line label.

Observe the following guidelines:

  • Place error-handling routines near the end of the procedure, just before the End Sub or End Function statement.
  • Avoid executing error-handling code when no error occurs by placing an Exit Sub or Exit Function statement just before the error handler's label. A Resume statement is typically used to continue execution of the macro after the error handler is done.
  • Use the Err object to return specific information about the error. (See the Visual Basic Help for more information about the Err object.)

Examples of Error-Handling Routines