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
Tom Ogilvy - 20 Feb 2007 04:10 GMT
no good definitive command. You can use END, but it clears all global
variables and does not clean up. Most recommend against using it.

Signature
Regards,
Tom Ogilvy
> I have a subroutine that opens a form which calls other routines. Is there
> a
[quoted text clipped - 8 lines]
>
> Thanks
Rich J - 20 Feb 2007 08:39 GMT
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.
> no good definitive command. You can use END, but it clears all global
> variables and does not clean up. Most recommend against using it.
[quoted text clipped - 11 lines]
> >
> > Thanks
Simon Lloyd - 20 Feb 2007 09:58 GMT
Rich J;7291927 Wrote:
> I have a subroutine that opens a form which calls other routines. Is
> there a
[quoted text clipped - 8 lines]
>
> 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

Signature
Simon Lloyd
Jon Peltier - 20 Feb 2007 16:29 GMT
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
_______
> I have a subroutine that opens a form which calls other routines. Is there
> a
[quoted text clipped - 8 lines]
>
> Thanks
Rich J - 20 Feb 2007 18:48 GMT
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.
> What I often do is change the sub into a function:
>
[quoted text clipped - 42 lines]
> >
> > Thanks