Microsoft Office Tutorials and References
In Depth Information
Lesson 17: Debugging Your Code
Debugging Your Code
Despite what you’ve always heard, there are really three sure things in life: death, taxes,
and errors in computer programs. There’s no avoiding it — errors will happen and they
will need to be fixed, whether the length of your VBA programming experience is 10 days
or 10 years.
You will need to learn the tools and techniques for debugging your code, so that
when things go wrong, you’ll be familiar with the resources that are at your disposal
for finding and fixing errors. Excel has many good built-in debugging tools. In addition,
other techniques exist that you’ll learn in this lesson about how to avoid errors in the
first place, and, believe it or not, how you can get errors to work for you instead of
WHAT is dEBugging?
A bug is an error in your code that can produce erroneous results, or, depending
on the nature of the bug, stop the code from executing altogether. In programming,
the term debugging refers to correcting an error in code, or the process of testing
a procedure for the possible existence of bugs that would need to be fixed if found.
you cAn do EVEryTHing rigHT And sTill HAVE A Bug
In the next section you’ll read about three causes of errors in VBA programming.
Actually, there is a fourth cause, which you have absolutely no control over, and
that is a bug in a software application itself. This is not in any way a specific
reference to a particular software company or to Microsoft. It’s a software industry
reality that new products are sometimes released with bugs, including known bugs
that are deemed to be benign but turn out to be a problem when used with Excel.