+ Reply to Thread
Results 1 to 6 of 6

Code for Exiting not working

  1. #1
    Registered User
    Join Date
    01-15-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    35

    Code for Exiting not working

    Hi there, simple problem, I think.

    I have used the attached code as a macro for a command button on a work sheet and it works fine, no problems.
    For a different workbook, I have a userform with a command button that I want the use to close the workbook.
    I add the code to the 'command button click', but it doesn't work...gives me the error message...
    "Compile error: Sub or function not defined' and the SaveQuit part of the first If statement is highlighted.

    Please Login or Register  to view this content.
    What's causing the error?

    Thanks in advance,
    Frank

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Code for Exiting not working

    hi Frank, as per your posted code the following code has the subroutines: SaveQuit, NoSaveQuit

    Solution is either to place those subroutines in the workbook with user form or replace names of the subroutines with actual codes for them

  3. #3
    Forum Contributor
    Join Date
    05-29-2013
    Location
    MD
    MS-Off Ver
    Excel 365
    Posts
    148

    Re: Code for Exiting not working

    Hi Frank,

    It's trying to run another sub called SaveQuit or NoSaveQuit, or Cancel...
    It can't find them - you need to copy them from the other workbook too, and put them in the same place.

    Also - the last line, you have Abd instead of Ans (maybe a typo when you were copying/pasting here?)

    Thanks,
    Duncan

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Code for Exiting not working

    If those programs are, indeed, available at the time of execution then try:

    Please Login or Register  to view this content.
    *it may be risky to call a routine Cancel - so, if that's one of your routines, change its name
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  5. #5
    Registered User
    Join Date
    01-15-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Code for Exiting not working

    Thanks everyone for the responses......I see what I did wrong. I have copied the other bits of code, (for SaveQuit, NoSaveQuit and Cancel) and it seems to work.
    Is there a 'cleaner' way to do this. Basically, I want a command button (Quit) to trigger a message box that gives the user the option to a) Save and Quit b) Don't save and Quit or c) Cancel message box without saving or quitting.

    Thanks again
    Frank

  6. #6
    Forum Contributor
    Join Date
    05-29-2013
    Location
    MD
    MS-Off Ver
    Excel 365
    Posts
    148

    Re: Code for Exiting not working

    Hi,

    Doesn't that happen anyway when you try to close a workbook (if you've made changes)...

    But if you did want to do that anyway the code would be as follows (presuming all it's doing is saving the current workbook or not...)

    Please Login or Register  to view this content.
    If you want it to do something when you hit cancel, then that's different

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Type Mismatch error ==> do some code before exiting sub
    By drawing.blanks in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-27-2012, 10:42 PM
  2. Code Procedure Problem: Exiting Select Statement
    By max57 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-05-2010, 12:21 AM
  3. Excel 2007 : Exiting Excel is not working properly
    By amg78 in forum Excel General
    Replies: 9
    Last Post: 04-29-2010, 06:33 PM
  4. Replies: 5
    Last Post: 03-21-2007, 01:00 AM

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