Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tom Tom is offline
external usenet poster
 
Posts: 25
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default 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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 339
Default 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




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
Excel won't quit JRS Excel Discussion (Misc queries) 1 September 27th 05 04:31 AM
Excel Won't Quit Rex Excel Programming 13 May 11th 05 01:51 PM
Another Quit problem Paul van Kan Excel Programming 4 December 30th 04 06:41 PM
If a called sub exit, how to the caller exit right away? luvgreen[_4_] Excel Programming 4 February 24th 04 05:06 PM
Excel won't quit Jeff[_23_] Excel Programming 0 October 24th 03 05:14 PM


All times are GMT +1. The time now is 07:54 AM.

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

About Us

"It's about Microsoft Excel"