![]() |
Exit-quit sub
Hello,
if I have many sub like this: Sub macro1() .... macro2 (calling macro2) .... End sub() Sub macro2() .... exit-quit ??? .... End sub() And in macro2 I need quit-exit all subs, not only macro2 (like Exit sub can do it), can you help me? tom |
Exit-quit sub
I think you could turn macro2 into a function that returns either false or
true. You can let it true if you want to exit immediately. The exit is of course done from macro1. If you get false, proceed in macro1 /Fredrik "Tom" wrote in message ... Hello, if I have many sub like this: Sub macro1() .... macro2 (calling macro2) .... End sub() Sub macro2() .... exit-quit ??? .... End sub() And in macro2 I need quit-exit all subs, not only macro2 (like Exit sub can do it), can you help me? tom |
Exit-quit sub
You can use the End statement to terminate all running VBA code.
Note that this will reset all global variables to their default values. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Tom" wrote in message ... Hello, if I have many sub like this: Sub macro1() .... macro2 (calling macro2) .... End sub() Sub macro2() .... exit-quit ??? .... End sub() And in macro2 I need quit-exit all subs, not only macro2 (like Exit sub can do it), can you help me? tom |
Exit-quit sub
Another couple of ways:
'a nice module level boolean variable Dim OkToContinue as boolean sub macro1() call macro2 if oktocontinue =false then exit sub end if end sub sub macro2 'do stuff if something = true then oktocontinue = false else oktocontinue = true end if end sub Or you can convert your subroutines to functions and return a boolean value. sub macro1 if func2 = false then exit sub end if end sub function func2 as boolean 'do stuff if something = true then func2 = false else func2 = true end if end function Tom wrote: Hello, if I have many sub like this: Sub macro1() .... macro2 (calling macro2) .... End sub() Sub macro2() .... exit-quit ??? .... End sub() And in macro2 I need quit-exit all subs, not only macro2 (like Exit sub can do it), can you help me? tom -- Dave Peterson |
All times are GMT +1. The time now is 04:30 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com