exit from nested macro

  • Thread starter Thread starter layla
  • Start date Start date
L

layla

Hi,
I call a subroutin inside my main macro.there is a conditional
statment inside the subroutin which if it true,the program must give a
message,and terminate.My code look something like this:
sub macro1()
if ...then
exit sub
end if
end sub

sub main()
call macro1
...
end sub
my question is:
How can I exit from from main if the bug is in the macro1
Thanks!
 
Hi Layla,

Try this

Sub main2()
On Error GoTo Error_main
macro2
MsgBox "Hello"
Exit_Main2:
Exit Sub
Error_main:
Resume Exit_Main2
End Sub

Sub macro2()
If True Then
Err.Raise 65536
End If
End Sub

As the error check is in Main2, Macro2 will return control to Main2

Hope this helps

Wkr,

JP
 
Hi Layla,

Try this

Sub main2()
    On Error GoTo Error_main
    macro2
    MsgBox "Hello"
Exit_Main2:
    Exit Sub
Error_main:
    Resume Exit_Main2
End Sub

Sub macro2()
    If True Then
        Err.Raise 65536
    End If
End Sub

As the error check is in Main2, Macro2 will  return control to Main2

Hope this helps

Wkr,

JP







- Show quoted text -

Hi,
I do not follow follow up with your code.However I use your idea in my
code,thanks!
Any idea,how I could stop the macro through the subroutin,using "stop
or applicatio.quit,or exit or.." without getting an error message.
 
Hi Layla,

If the code generates an run-time error, check your settings in VBE.

Alt-F11, Tools, Options, General, Error trapping
Select "Break on Unhandled errors".

Do not use application.quit because that will bomb out Excel.

If you want to stop all code, use "End".

Wkr,

JP



Hi Layla,

Try this

Sub main2()
On Error GoTo Error_main
macro2
MsgBox "Hello"
Exit_Main2:
Exit Sub
Error_main:
Resume Exit_Main2
End Sub

Sub macro2()
If True Then
Err.Raise 65536
End If
End Sub

As the error check is in Main2, Macro2 will return control to Main2

Hope this helps

Wkr,

JP







- Show quoted text -

Hi,
I do not follow follow up with your code.However I use your idea in my
code,thanks!
Any idea,how I could stop the macro through the subroutin,using "stop
or applicatio.quit,or exit or.." without getting an error message.
 
Back
Top