Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default If a called sub exit, how to the caller exit right away?

Good morning! I have a question to ask experts. The main sub will a sub2, if
there is error in sub2, sub2 will pop a message and exit. How can I make the
main sub exit right away without running other code behind calling sub2?
thanks.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default If a called sub exit, how to the caller exit right away?

Hi
one way:
make your second sub a function which return FALSE or an error code. In
your main sub you can use somethin like

sub main_sub()
....
ret = subfunction2
If not ret then exit sub
....
end sub


--
Regards
Frank Kabel
Frankfurt, Germany

luvgreen wrote:
Good morning! I have a question to ask experts. The main sub will a
sub2, if there is error in sub2, sub2 will pop a message and exit.
How can I make the main sub exit right away without running other
code behind calling sub2? thanks.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default If a called sub exit, how to the caller exit right away?

On way is to put the error handler in Sub1 and not in sub2.


--
Regards,
Tom Ogilvy

"luvgreen" wrote in message
...
Good morning! I have a question to ask experts. The main sub will a sub2,

if
there is error in sub2, sub2 will pop a message and exit. How can I make

the
main sub exit right away without running other code behind calling sub2?
thanks.





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default If a called sub exit, how to the caller exit right away?

You should make Sub2 a function that returns a value, and then
continue or discontinue code in MainSub based on the return value
of Sub2. E.g.,

Sub MainSub()
Dim Continue As Boolean
Continue = Sub2()
If Continue = False Then
Exit Sub
End If
End Sub

Function Sub2() As Boolean
' your code
If Something Then
Sub2 = False
Exit Function
End If
' rest of code
End Function


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"luvgreen" wrote in message
...
Good morning! I have a question to ask experts. The main sub

will a sub2, if
there is error in sub2, sub2 will pop a message and exit. How

can I make the
main sub exit right away without running other code behind

calling sub2?
thanks.





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default If a called sub exit, how to the caller exit right away? - Thanks all!

Thank you all for your kind help. It worked.
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
Text Box exit Jamal[_2_] Excel Programming 10 January 5th 04 03:57 PM
Exit Sub? Eva Shanley[_2_] Excel Programming 3 December 24th 03 02:15 PM


All times are GMT +1. The time now is 03:36 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"