Microsoft Office Tutorials and References
In Depth Information
If your error handler is able to fix the problem that raised the error to begin with, you will
want to resume execution of your procedure. That is done by using the Resume command.
Placed inside of an error handler, it resumes execution with the statement that generated the
error originally.
At times, the error handler might not be able to correct the problem, but if the error itself was
not fatal to the execution, the error would not cause the rest of the procedure to fail. If that’s
the case, you can resume execution of the procedure by using the Resume Next statement.
This continues execution with the statement immediately after the statement that raised the
error. You can also specify execution to resume at a specific statement by using the Resume
line statement. This will continue execution at the statement named by line .
The following code fragment illustrates a common method of using error handlers:
On Error Goto ErrorHandler
Exit Sub
MsgBox(str$(Err) & ": " & Err.Description, vbInformation, "Error Handler")
Resume FinishedSub
This rather lengthy, though hopefully complete, chapter has covered all of the basic skills you
need to begin creating VBA macros. You’ve learned how to define and assign values to vari­
ables, to control the flow of your programs using loops and tests, and to handle any errors
that come along. In Chapter 5, you’ll learn how to create and use procedures that contain
your VBA code.
Search JabSto ::

Custom Search