View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Paul Robinson Paul Robinson is offline
external usenet poster
 
Posts: 208
Default HELP: error handling in VBA

Hi
Use "on error resume next" when you are not bothered what the error is
or want to use the error. Call a sub if you want to handle the error
or use goto.
As an example of using "on error resume next", if you want to add a
comment to a cell and put in some text you may not be bothered if the
comment and text exists already. In that case, the error is thrown
(but ignored) if the comment already exists but is not thrown if there
is no comment there, and you can add it. Your code is simpler - you
don't need to check the comment is there. This principle can be used
for lots of things - do variables exist, do range names exist yet, do
sheets exist yet etc.
regards
paul

On Mar 8, 6:47*pm, sam wrote:
Hi All,

Why do we use "On error resume next" shouldnt we be resolving those errors.

For eg: if we are sending important email notifications through excel VBA
which affect management decisions, shouldnt we be avoiding to user "On error
resume next"? IF for some reason there is an error and an email is not sent
it might affect a lot of things.

My concern is: how do we handle error is this situations? is there a better
way to handle errors, rather than using "On error resume next" statement?

Thanks in advance.