ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to Stop a Macro if a 'Call' macro was used (https://www.excelbanter.com/excel-programming/414848-how-stop-macro-if-call-macro-used.html)

Corey[_2_]

How to Stop a Macro if a 'Call' macro was used
 
Is ther a way to Cancel a CommandButton on a form via a Module Sub Routine ?

I can have :
Userform1.CommandButon2.Cancel
but it does not STOP the macro from running that called the other macro in
the module, but returns an error.

Is ther a way to STOP/CANCEL a CommandButton continuing from a Module code?

Corey....



Susan

How to Stop a Macro if a 'Call' macro was used
 
you'd have to code in the condition..........

if <condition then
exit sub
end if

when it exits then it would go back to the first macro that called
it. once it's in the middle of running the only way to break out of
it is Ctrl+Break.
hth
:)
susan



On Jul 30, 7:25*am, "Corey" wrote:
Is ther a way to Cancel a CommandButton on a form via a Module Sub Routine ?

I can have :
Userform1.CommandButon2.Cancel
but it does not STOP the macro from running that called the other macro in
the module, but returns an error.

Is ther a way to STOP/CANCEL a CommandButton continuing from a Module code?

Corey....



Corey[_2_]

How to Stop a Macro if a 'Call' macro was used
 

I do nto know how i can place an IF condition though.

I use a :
Sub CommandButton2_Click()
'code blah blah blah
........
Call Macro1
end Sub

How would i place a condition in the Call Macro1 to Exit the CommandButton
Sub IF the Macro1 Changes something?

Corey....

"Susan" wrote in message
...
you'd have to code in the condition..........

if <condition then
exit sub
end if

when it exits then it would go back to the first macro that called
it. once it's in the middle of running the only way to break out of
it is Ctrl+Break.
hth
:)
susan



On Jul 30, 7:25 am, "Corey" wrote:
Is ther a way to Cancel a CommandButton on a form via a Module Sub Routine
?

I can have :
Userform1.CommandButon2.Cancel
but it does not STOP the macro from running that called the other macro in
the module, but returns an error.

Is ther a way to STOP/CANCEL a CommandButton continuing from a Module
code?

Corey....




Susan

How to Stop a Macro if a 'Call' macro was used
 
you'd need some sort of a boolean value, then......

call Macro1
'then when it comes back to
'commandbutton2, check your
'boolean
if myboolean = true then
exit sub
end if

and in the macro1 sub, you'll need to set the boolean before you exit
the macro1 sub.........

if <condition then
myboolean=true
exit sub
'goes back to commandbutton2 here
end if

make sure your myboolean variable is a public variable, though, so it
will carry over between the subs.
hth
susan



On Jul 30, 8:24*am, "Corey" wrote:
I do nto know how i can place an IF condition though.

I use a :
Sub CommandButton2_Click()
'code blah blah blah
.......
Call Macro1
end Sub

How would i place a condition in the Call Macro1 to Exit the CommandButton
Sub IF the Macro1 Changes something?

Corey....

"Susan" wrote in message

...
you'd have to code in the condition..........

if <condition then
exit sub
end if

when it exits then it would go back to the first macro that called
it. *once it's in the middle of running the only way to break out of
it is Ctrl+Break.
hth
:)
susan

On Jul 30, 7:25 am, "Corey" wrote:



Is ther a way to Cancel a CommandButton on a form via a Module Sub Routine
?


I can have :
Userform1.CommandButon2.Cancel
but it does not STOP the macro from running that called the other macro in
the module, but returns an error.


Is ther a way to STOP/CANCEL a CommandButton continuing from a Module
code?


Corey....- Hide quoted text -


- Show quoted text -



Corey[_2_]

How to Stop a Macro if a 'Call' macro was used
 
Thank you will give that a try.
"Susan" wrote in message
...
you'd need some sort of a boolean value, then......

call Macro1
'then when it comes back to
'commandbutton2, check your
'boolean
if myboolean = true then
exit sub
end if

and in the macro1 sub, you'll need to set the boolean before you exit
the macro1 sub.........

if <condition then
myboolean=true
exit sub
'goes back to commandbutton2 here
end if

make sure your myboolean variable is a public variable, though, so it
will carry over between the subs.
hth
susan



On Jul 30, 8:24 am, "Corey" wrote:
I do nto know how i can place an IF condition though.

I use a :
Sub CommandButton2_Click()
'code blah blah blah
.......
Call Macro1
end Sub

How would i place a condition in the Call Macro1 to Exit the CommandButton
Sub IF the Macro1 Changes something?

Corey....

"Susan" wrote in message

...
you'd have to code in the condition..........

if <condition then
exit sub
end if

when it exits then it would go back to the first macro that called
it. once it's in the middle of running the only way to break out of
it is Ctrl+Break.
hth
:)
susan

On Jul 30, 7:25 am, "Corey" wrote:



Is ther a way to Cancel a CommandButton on a form via a Module Sub
Routine
?


I can have :
Userform1.CommandButon2.Cancel
but it does not STOP the macro from running that called the other macro
in
the module, but returns an error.


Is ther a way to STOP/CANCEL a CommandButton continuing from a Module
code?


Corey....- Hide quoted text -


- Show quoted text -





All times are GMT +1. The time now is 09:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com