How do I exit a chained macro under a certain condition?

peskywinnets

Registered User.
Local time
Today, 09:19
Joined
Feb 4, 2014
Messages
578
I have some macros which are chained.

These macros are mainly running queries but sometimes, there's a bit of VBA code being called (via Run code).

The VBA code is checking for certain conditions....what I need is to cease all Macros from running when my code traps a certain scenario....what's the command to stop all macros running? (i.e. the present Macro that's running and those that would run immediately afterwards)

Many thanks.
 
In a macro there's a StopAllMacros action, so you can try that. If the VBA needs to trigger it, you could set a TempVar in VBA and check it in the macro. I'm not a macro user, so I'd convert it all to VBA where you have more control.
 
Thanks.... the StopAllMacros action is for use within the macro interface ...what I seek is when some VBA code is being run (called via the Macro), that the VBA code itself can Stop all Macros

I therefore converted StopAllMacros to VBA & this is what I got....


Code:
Function Macro1()
On Error GoTo Macro1_Err

    End

Macro1_Exit:
    Exit Function

Macro1_Err:
    MsgBox Error$
    Resume Macro1_Exit

End Function

....I'm not sure exit function is going to work for me, because if I use 'exit function', then control will be handed back to the originating macro that ran the VBA code ....& the Macro will then simply continue along its chain? Or am I missing the point?!!
 
I'm not a macro user, but I don't think VBA code can stop the macros. My suggestion was to set the value of a TempVar in the VBA code if you want to stop, then test that value in the macro after the VBA code runs.
 

Users who are viewing this thread

Back
Top Bottom