exit sub


Posted by David on August 08, 2000 1:43 AM

is there a way to stop a macro dead in its tracks.

I am trying to use end sub and about halfe the time it doesn't stop it.

This is in the original macro. I want it to stop where it is marked.

If ICounter = 400 Then
Answer = MsgBox("That date was not found. Would
_you Like to try to add this Date to the
_database", vbOKCancel, "Date Missing")
If Answer = vbOK Then
Application.Run "'book1.xls'!Unhideall"
Workbooks(shortbookname).Activate
Sheets("summary").Select
Range("B1") = Idate
Call runadddate(part)
Application.Run "'sheet1.xls'!macro1"
Else
Call ERRORCODE(3)
Exit Sub 'Want to stop here
End If
End If

Posted by Ivan Moala on August 08, 0100 4:03 AM

Hi David
Your routine works as given, that is
it stops @ exit sub IF you select Cancel ??
Do you want it to exit your routine here ??
when the user selects cancel OR have you something
else in mind.
Please clarify


Ivan

Posted by David on August 08, 0100 6:18 AM

If they hit cance I want the thing to stop in its tracks. Dying would be fine but it keeps running from time to time past that exit sub.
When cancel is hit it should run error code then die.

Posted by david on August 09, 0100 9:24 AM

It even runs after that.

Posted by ML on August 09, 0100 11:32 AM

Try this:

If ...=vbOkay Then
...
...
ELSE
A=1
call Errorcode(3)
End if
If A=1 then end

place a breakpoint at the ELSE statement
and step through it after running and
canceling the box.



Posted by Michael Liu on August 08, 0100 1:37 PM


Does it always seem to run errorcode when you hit cancel?
If so, the macro should always stop after it gets to the Exit Sub
line. Do you have another procedure calling this one?
If this is the procedure you initially run, then Exit Sub should
produce the desired result. If it is called by another procedure, then
Exit Sub will just exit the current procedure and return to the line
after the one that called it.
You could also try using "End" to stop everything.
There's some warnings in the help screens about "End", so
use with caution.