Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Call a subroutine using variable subroutine name | Excel Discussion (Misc queries) | |||
VB subroutine | Excel Programming | |||
How to make userform disappear while called subroutine is running | Excel Programming | |||
Referencing a file name within a called subroutine | Excel Programming | |||
Public subroutine called from a private sub | Excel Programming |