+ Reply to Thread
Results 1 to 8 of 8

Exit all subs

  1. #1
    Registered User
    Join Date
    08-14-2009
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    12

    Exit all subs

    I have a user form that is called from inside a sub. I want to stop all code running if the user form is just deactivated. Obviously putting exit sub in the user form deactivate just stops that sub but when it goes back to the calling function it continues to run. Is there a way of ending all code or passing a vaiable back from the form in the parent funtion?

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Exit all subs

    Perhaps you mean

    Please Login or Register  to view this content.
    eg:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-14-2009
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Exit all subs

    i have tried this but by using end in in sub two sub three is still called. End only works on that sub and the sub one will then continue to excecute the rest of the code after it

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Exit all subs

    Without seeing your own code it's hard to pass comment, but using my example - if you run Sub one() and click "Yes" on subsequent MsgBox Sub three() is not invoked (no "Invoked" dialog is generated).

  5. #5
    Registered User
    Join Date
    08-14-2009
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Exit all subs

    This is the code for the main sub

    Please Login or Register  to view this content.
    here is the code for the user form

    Please Login or Register  to view this content.

    how do pass response back from the form to the main sub
    Last edited by boc_est1986; 08-18-2009 at 06:36 AM. Reason: post did not comply with rule #3 of the forum rules

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Exit all subs

    You would use the Terminate Event, ie:

    Please Login or Register  to view this content.
    No need to pass variable back to main routine if you intend to just exit the code altogether.

  7. #7
    Registered User
    Join Date
    08-14-2009
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Exit all subs

    ok thanks its working now

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Exit all subs

    Be careful of the use of End. It will reset all module/project level variables.

    The problem is that the response variable is local to the caller routine.
    You either need to use a public variable or a private variable within the userform that you can read.

    public variable approach.
    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1