Stopping a 'multi-level' procedure

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have some longer macros that have the structure:
sub toplevel()
call nextlevel 'or call nextlevel1(a,b,c)
'and in the nextlevel code
call lower_level 'or call lower_level2(d,e,f)

In many of the lower_level procedures there is error checking where 'exit
sub' is used to stop execution. It's getting tiresome to code all of the
'back track' conditions in order to stop the execution of the toplevel sub.

Is there an Excel vba way of immediately stopping the top most sub when a
lower level sub contains an error?

Thanks,
 
Put the error handler only in the initial/toplevel routine. If an error
occurs, vba moves up the stack until it finds an error handler in one of the
calling routines. If it finds none, then it errors, otherwise the first
error handler it finds will handle the error. So you could end at that
point (in the top level routine).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top