Enabling an error trap is done with the On Error statement. This establishes error handling in your code. If an error occurs, it detours program execution another place in your program that you specify. Where execution is redirected depends on what you type after the words On Error, as is seen in the following code:

On Error GoTo ErrHandler
‘Code with error appears here
Exit Sub
ErrHandler:
‘Error handling code appears here