Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default How To Quit Subroutine from a called subroutine

I have a subroutine that opens a form which calls other routines. Is there a
simple way to quit all and stop running everything from the called routine?

When the cursor returns to the calling routine I don't want the rest of that
code to run in some situations.
I can add a test right after it returns but thought there might be a
definitive command.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How To Quit Subroutine from a called subroutine

no good definitive command. You can use END, but it clears all global
variables and does not clean up. Most recommend against using it.

--
Regards,
Tom Ogilvy


"Rich J" wrote in message
...
I have a subroutine that opens a form which calls other routines. Is there
a
simple way to quit all and stop running everything from the called
routine?

When the cursor returns to the calling routine I don't want the rest of
that
code to run in some situations.
I can add a test right after it returns but thought there might be a
definitive command.

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default How To Quit Subroutine from a called subroutine

That is actually exactly the command I needed. It is in a Set Up routine and
if certain dates have not been entered, Set Up needs to stop running and a
calendar sheet left open for amending. The macro would keep running and
close the sheet though without the necessary changes. Now, after making the
changes, the user just pushes the Set Up button again and won't have to go to
that part of the program again. It couldn't be a more simple solution.

Thank you once again Tom.


"Tom Ogilvy" wrote:

no good definitive command. You can use END, but it clears all global
variables and does not clean up. Most recommend against using it.

--
Regards,
Tom Ogilvy


"Rich J" wrote in message
...
I have a subroutine that opens a form which calls other routines. Is there
a
simple way to quit all and stop running everything from the called
routine?

When the cursor returns to the calling routine I don't want the rest of
that
code to run in some situations.
I can add a test right after it returns but thought there might be a
definitive command.

Thanks




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How To Quit Subroutine from a called subroutine


Rich J;7291927 Wrote:
I have a subroutine that opens a form which calls other routines. Is
there a
simple way to quit all and stop running everything from the called
routine?

When the cursor returns to the calling routine I don't want the rest of
that
code to run in some situations.
I can add a test right after it returns but thought there might be a
definitive command.

ThanksThe simple solution is to add a message box as VbOkCancel or VbYesNo you

would use it in this fashion

Code:
--------------------
If MsgBox("Continue?", vbYesNo, "Test") = vbNo Then
Exit Sub
End If
--------------------
regards,
Simon


--
Simon Lloyd
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default How To Quit Subroutine from a called subroutine

What I often do is change the sub into a function:

Function MySub() As Boolean

If the function finishes successfully, I assign it a value of True;
otherwise the function returns False. Then in the calling sub I test the
value of the function, and if False, I can exit gracefully from this sub as
well:

Sub Main()

' blah

bTest = MySub
If Not bTest then
' Bail Out
GoTo ExitSub
End If

' yada

ExitSub:

' clean up

End Sub

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"Rich J" wrote in message
...
I have a subroutine that opens a form which calls other routines. Is there
a
simple way to quit all and stop running everything from the called
routine?

When the cursor returns to the calling routine I don't want the rest of
that
code to run in some situations.
I can add a test right after it returns but thought there might be a
definitive command.

Thanks





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default How To Quit Subroutine from a called subroutine

Thank you both for additional suggestions. The routine is for automatically
transferring all the worksheets (sometimes over 100) created in an older
version of a workbook I developed to the updated workbook it is running from.
I have tried to keep the program itself fairly intuitive for users. I put in
several interview questions during Set UP in msgbox's to make sure that the
new workbook will have the correct calendar it needs. Stopping the Set UP
cold if they haven't already made sure that it is correct is exactly what I
needed. It closes the Set UP form and leaves the calendar sheet open for
amending. If the calendar is wrong in the older workbook (which happens more
often than I like to hear) then each sheet is automatically corrected if the
calendar is correct in the new workbook.

"Jon Peltier" wrote:

What I often do is change the sub into a function:

Function MySub() As Boolean

If the function finishes successfully, I assign it a value of True;
otherwise the function returns False. Then in the calling sub I test the
value of the function, and if False, I can exit gracefully from this sub as
well:

Sub Main()

' blah

bTest = MySub
If Not bTest then
' Bail Out
GoTo ExitSub
End If

' yada

ExitSub:

' clean up

End Sub

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"Rich J" wrote in message
...
I have a subroutine that opens a form which calls other routines. Is there
a
simple way to quit all and stop running everything from the called
routine?

When the cursor returns to the calling routine I don't want the rest of
that
code to run in some situations.
I can add a test right after it returns but thought there might be a
definitive command.

Thanks




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
Call a subroutine using variable subroutine name dhstein Excel Discussion (Misc queries) 3 July 26th 09 08:28 PM
VB subroutine Noel Rietman Excel Programming 0 October 19th 06 07:50 PM
How to make userform disappear while called subroutine is running Cornelia Excel Programming 2 June 16th 06 10:47 PM
Referencing a file name within a called subroutine Matt[_32_] Excel Programming 1 July 24th 05 08:21 AM
Public subroutine called from a private sub Neil Bhandar[_2_] Excel Programming 1 January 15th 04 10:23 PM


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