Chapter 12

Error-Handling Techniques

IN THIS CHAPTER

Bullet Understanding the difference between programming errors and runtime errors

Bullet Trapping and handling runtime errors

Bullet Using On Error and Resume statements

Bullet Finding out how you can use an error to your advantage

To err is human. To anticipate errors is divine. When working with VBA, you should be aware of two broad classes of errors: programming errors and runtime errors. This chapter is all about runtime errors.

A well-written program handles errors the way Fred Astaire danced: gracefully. Fortunately, VBA includes several tools to help you identify errors — and then handle them gracefully.

Types of Errors

If you’ve tried any of the examples in this book, you have probably encountered one or more error messages. Some of these errors result from bad VBA code. For example, you may spell a keyword incorrectly or type a statement with the wrong syntax. If you make such an error, you won’t even be able to execute the procedure until you correct it.

This chapter doesn’t deal with those types of errors. Instead, it focuses on runtime errors ...

Get Excel VBA Programming For Dummies, 5th Edition 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.