Trapping Errors in Your Code

Both VB and VBA provide the same mechanism for you to handle errors—the On Error statement. This line of code sets an option, which is used until the end of the current procedure or until another On Error statement is encountered. The option you set determines exactly what occurs when an error is encountered in your code, and can be one of three different options:

  • On Error GoTo <Label>

  • On Error Resume Next

  • On Error GoTo 0

The first option, On Error GoTo <Label>, indicates that, from that line on (until the end of the procedure or another On Error statement), if an error occurs, the program should immediately jump to the specified Label and execute the code found in that location. An example of this type of error handling ...

Get Exchange & Outlook®: Constructing Collaborative Solutions 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.