VBA Error Handling

In a perfect world, there wouldn’t be a need for VBA error handling code at all. The reality is that it doesn’t matter how careful you are when you write your code; undoubtedly, you will have errors. If an application doesn’t handle errors in a professional manner, users will become frustrated, even if the application is very refined.\

The Microsoft Office products provide the option to debug code on the fly. This can be either a blessing or a disaster waiting to happen. If you’re in a large organization using Office 2000, you might find yourself frequently running to users’ desks and debugging code right at their desktops. Obviously, this isn’t the preferred manner of handling a project deployment, but if you are doing extensive Office 2000 development, you’ll probably run into this.
A comprehensive error handler can provide feedback to you as a developer and help you understand where the application is breaking down. Keep in mind that any error messages displayed to an end user should be clear and concise. They should also explain exactly what steps the user should take. If they are going to lose information, let them know in the error message (this will save you from being the one to tell them).
Sometimes errors are referred to as bugs. Bugs can be anything from a mistake in the functionality provided (undocumented features) to a coding error that breaks execution of the program from which you cannot recover. Hopefully, you will be conscious of the possibility of bugs and code appropriately. This means that you will try to avoid losing a user’s data should the program crash. There will always be instances where data cannot be recovered, but you should try to minimize both the number of these occurrences as well as the amount of data that is lost.

Debugging is the process of locating bugs in your application and fixing them. VBA provides several tools to help analyze how your application operates. These debugging tools are very powerful when used correctly. Frequently, a programmer finds one or two very rudimentary ways of debugging an application and tries to work them into his debugging arsenal. This is okay in the beginning, but you should always strive to find the most efficient way of debugging your code.

Popularity: 1% [?]

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • MisterWong
  • Y!GG
  • Webnews
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit

Leave a Reply




You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>