#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 85
Default exit sub

how do i get out of all subs upon a certain event?

sub1()
call sub2
'more code here--i do not want sub1 to get this far unless sub2 runs all the
way through
end sub

sub2()
if 1=1 then
exit sub 'i want this to quit sub1 as well as sub2
end if
end sub

there may be more embedded subs, so i don't think i can specify which sub to
exit (if that is even possible).
thanks, mike allen


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default exit sub

your example is a bit confusing. but if code stops before
a call, the call is never made. move your call to the end
of sub1(or at least after the exit sub command.) Some
where you will have to add a exit sub command in sub1 to
stop it from call sub2. now...where to put the exit sub
command. you didn't provide enought information to answer
that.
-----Original Message-----
how do i get out of all subs upon a certain event?

sub1()
call sub2
'more code here--i do not want sub1 to get this far

unless sub2 runs all the
way through
end sub

sub2()
if 1=1 then
exit sub 'i want this to quit sub1 as well as sub2
end if
end sub

there may be more embedded subs, so i don't think i can

specify which sub to
exit (if that is even possible).
thanks, mike allen


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 85
Default exit sub

my placements are as i want them. to clarify: i am simply running sub1,
which does certain things, then calls sub2. now in sub2, certain things are
done, then IF something happens (1=1 in this case), i want to exit
everything. exiting sub2 is easy, but i don't want it going back and
finishing sub1 (after "call sub2"), which is what it does in this example.
this may help:
sub1()
'various code is written here
call sub2
'more various code is written here, but do not want to go this far unless
sub2 is completed
end sub

sub2()
'various code is written here
if 2=2 then
exit sub 'this is where i need to exit not only sub2, but sub1 as well
endif
'more various code is written here
end sub

thanks, mike allen

"Frank Stone" wrote in message
...
your example is a bit confusing. but if code stops before
a call, the call is never made. move your call to the end
of sub1(or at least after the exit sub command.) Some
where you will have to add a exit sub command in sub1 to
stop it from call sub2. now...where to put the exit sub
command. you didn't provide enought information to answer
that.
-----Original Message-----
how do i get out of all subs upon a certain event?

sub1()
call sub2
'more code here--i do not want sub1 to get this far

unless sub2 runs all the
way through
end sub

sub2()
if 1=1 then
exit sub 'i want this to quit sub1 as well as sub2
end if
end sub

there may be more embedded subs, so i don't think i can

specify which sub to
exit (if that is even possible).
thanks, mike allen


.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default exit sub

Mike: The way you have your example written is a bit confusing, because it
doesn't look like there's any more code in sub1 to run after sub2 ends for
whatever reason. But assuming there is more code, can you set a boolean
True/False in sub2 and pass it to sub1? Then maybe:
sub1()
'various code is written here
call sub2
'more various code is written here, but do not want to go this far unless
sub2 is completed

***
If bolEndMe = True
GoTo Bye
End If
' more code

' just before End Sub statement
Bye:
end sub

sub2()
'various code is written here
if 2=2 then
exit sub 'this is where i need to exit not only sub2, but sub1 as well
endif
'more various code is written here
end sub

thanks, mike allen


When sub2 exits, it will drop back into sub1 right after the call. If the
boolean is set to indicate that, based on sub2, you want to end all code, it
would process the GoTo and drop you down to the End Sub.

HTH
Ed


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default exit sub

"mike allen" skrev i melding
...
how do i get out of all subs upon a certain event?

sub1()
call sub2
'more code here--i do not want sub1 to get this far unless sub2 runs all

the
way through
end sub


Hi Mike

You want to evaluate the RESULT of a macro. Those macros are not Subs (which
in reality are Functions returning Void, nothing) but Functions (returning
whatever you ask them to). See if the following makes sense to you. The test
in 2 here is whether the seconds on the clock is odd or even.

Sub Main()
Call Code1
If Code2 = True Then
Call Code3
End If
End Sub

Sub Code1()
MsgBox "Hello world from 1"
End Sub

Function Code2() As Boolean
If Second(Now) Mod 2 = 0 Then Code2 = True
MsgBox Code2 & " from 2"
End Function

Sub Code3()
MsgBox "Hello world from 3"
End Sub

HTH. Best wishes Harald


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exit Sub Jeff Excel Discussion (Misc queries) 2 March 1st 08 06:21 PM
Run when exit PH NEWS Excel Worksheet Functions 1 July 18th 06 03:53 PM
Exit via macro only? Brisbane Rob Excel Discussion (Misc queries) 1 October 13th 05 01:16 PM
If a called sub exit, how to the caller exit right away? luvgreen[_4_] Excel Programming 4 February 24th 04 05:06 PM
Exit Sub? Eva Shanley[_2_] Excel Programming 3 December 24th 03 02:15 PM


All times are GMT +1. The time now is 05:22 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"