View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Zone[_3_] Zone[_3_] is offline
external usenet poster
 
Posts: 373
Default exiting the whole macro

Maybe this will help. Notice that the error ripples back to the first
routine. James

Sub Sub1()
On Error GoTo ErrHandler
Sub2
MsgBox "No error found"
Exit Sub
ErrHandler:
MsgBox "Error " & Err & Chr(13) & Error
End Sub

Sub Sub2()
Sub3
End Sub

Sub Sub3()
Error 15
End Sub

"tigoda" wrote in message
...
that works, but only if the exit sub is in the second sub, not in a 3rd or
4th,

i want this to be attached to some error handling, so calling the sub that
has the 'bomb out of everytihng' code could happen any time,

there will be a sub to deal with errors and to print meaning fill text
boxes
to help the user with the error, this error sub will be either 2 or 3 subs
in
and will be called from the on err bit,


"Zone" wrote:

Sub test()
If Test_2() = "exit now" Then Exit Sub
MsgBox ("fail")
End Sub

Function Test_2() As String
'the code I need has to go here!
Test_2 = "exit now"
End Function


"tigoda" wrote in message
...


I have the following example:

Sub test()
call Test_2
MsgBox ("fail")
End Sub

Sub Test_2()
'the code I need has to go here!
End Sub

in the second sub I need a command/section of code that will exit the
whole
macro, currently end sub and exit sub just exit the second sub and
continue
running the first sub (displaying the msg box "fail" as a test)

there has to be a way to safety bomb out of the macro without resorting
to
ending and closing the whole sheet,

can anyone help?