Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Exit Sub | Excel Discussion (Misc queries) | |||
Run when exit | Excel Worksheet Functions | |||
Exit via macro only? | Excel Discussion (Misc queries) | |||
Text Box exit | Excel Programming | |||
Exit Sub? | Excel Programming |