Exit a Macro

J

jerry chapman

While debugging a macro, there are times I would like to exit the macro at a
certain point. Is there a command to do that?
 
J

Jezebel

Do you really mean exit, or just stop so you can see what's going on?

Stop, as Howard suggests, is one option, although strictly speaking this
doesn't exit the macro -- having stopped, you can resume from that point by
pressing F5 or F8.

You can insert a breakpoint by selecting any instruction line and pressing
F9 -- execution will halt at that point.

You can use a Debug.Assert statement. Add the condition under which
execution should halt, or use Debug.Assert FALSE for always.

But if you really mean exit the macro, use Exit Sub.
 
J

Jezebel

NO NO NO. "End" is included in VB/VBA for backward compatability ONLY. NEVER
use it. a) it is unnecessary, and b) in many circumstances it will cause the
application the crash. Using End puts your documents at risk.
 
M

Malcolm Smith

NO NO NO. "End" is included in VB/VBA for backward compatability ONLY.
NEVER
use it. a) it is unnecessary, and b) in many circumstances it will
cause the
application the crash. Using End puts your documents at risk.

I cannot agree more. In this day and age we are supposed to close
everything properly. By this I mean we are supposed to exit each loop or
nested step properly and, where we have to, we clean up any created
objects.

End is something which should never be used. People preach about never
using Goto statements but really they forces of Good and Right should be
out there on the streets with the burning torches fighting off the use of
the End statement.

These days don't think of VBA as a mere 'macro' but actually as a VBA
application.

- Malc
 
J

Jezebel

It's actually worse than mere programming elegance. The mere inclusion of
'End' in your code can cause the whole damn app to crash.
 
M

Malcolm Smith

Indeed, the same in VB.

I was just trying to wrap the statement up nicely! :)

But, whatever, the End statement should be taken out behind the barn and
shot.
 

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

Top