Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a way to have a macro cancel all other macros running 2

Status
Not open for further replies.

coolcarls

Technical User
Jan 19, 2002
182
0
0
US
I have a series of macros and commands initiated when I click a macro button, the first thing that happens is a UserForm is shown, I want to put a Cancel button on the form and if it's pressed it stops everything and closes the userform and just stops?
Thanks in advance!
Carl
 
What I've done is Assign a very simple macro called EndProg to the Cancel button:-

Sub EndProg
MsgBox "Application Halted", vbCritical, "Bye, Bye"
End
End Sub

This will stop the macro. You can add in line to go back to the sheet you started with. You might also want to add in Application.ScreenUpdating = True if you've already put Application.ScreenUpdating = False in the running macro.

Hope this helps

Des.
Barking, Essex
 
If you want a more gentle approach, structure your series of macros so that they are a little more dependent. There are a couple ways of doing this according to your taste.

Assuming your code looks like this:

Sub Main
Step1
Step2
Step3
End Sub

You could set up a global variable and write:

Dim OkToContinue as Boolean
Sub Main
Step1
If OkToContinue then Step2
If OkToContinue then Step3
End Sub

Another way is to make the steps functions instead of subs and return True or False according to continue or not:

Sub Main
If Step1 then
If Step2 then
Step3
End If
End If
End Sub

 
Just when you start to think you know a little, you guys come back with all this knowledge, amazing! Thank you VERY much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top