+ Reply to Thread
Results 1 to 10 of 10

How to disable "X" for closing workbook and force use of button

  1. #1
    Registered User
    Join Date
    08-05-2013
    Location
    Swansea
    MS-Off Ver
    Excel 2003
    Posts
    3

    How to disable "X" for closing workbook and force use of button

    I need to be able to force users to click a button to close the workbook and not the "X" in top right corner.

    Each user has their own copy of the workbook and it saves to a central location but only when they use the "Exit" button. If they close it via the "X" then a Macro to save the work doesn't run.

    I need to be able to disable the use of the "X" and prompt the user to close via the exit button. I've read about how to do it when using userforms but this doesn't seem to do the job.

    Any help please?



    PS. sorry if this has been posted before but I couldn't find anything relating to my issue.

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: How to disable "X" for closing workbook and force use of button

    do you mean the File-Exit menu option, or a button you have created? if it's a custom button you could use the workbook_beforeclose event instead
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    08-05-2013
    Location
    Swansea
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: How to disable "X" for closing workbook and force use of button

    I've created a button to exit the workbook and perform the necessary functions, I just need to stop using the "X" in the top corner or the file exit menu option as if they then decice to save the file it will overwrite the original

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: How to disable "X" for closing workbook and force use of button

    Putting this:
    Please Login or Register  to view this content.
    In your ThisWorkbook object in the vba project will effectively disable the X button. However, you will need to change your button macro to disable events before trying to close the workbook that way also. Alternatively you can change the X button to run your close routine using something like:

    Please Login or Register  to view this content.
    You will still need to disable events to close your workbook from a macro.

  5. #5
    Registered User
    Join Date
    08-05-2013
    Location
    Swansea
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: How to disable "X" for closing workbook and force use of button

    Perfect. Thanks for the help

  6. #6
    Registered User
    Join Date
    01-24-2017
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    6

    Re: How to disable "X" for closing workbook and force use of button

    I tried using this code but have run into a problem. If the user clicks on the close button the code works fine. If the user clicks a second time the code does not work and the user gets the usual Save, Don't Save, or Cancel window from Excel. How can the Close "X" be permanently disabled?

    Thank you.

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: How to disable "X" for closing workbook and force use of button

    In a module
    Please Login or Register  to view this content.
    In workbook module
    Please Login or Register  to view this content.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  8. #8
    Registered User
    Join Date
    01-24-2017
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    6

    Re: How to disable "X" for closing workbook and force use of button

    Thank you for your reply. I just tried the code and it still allows the user to exit using the close "X" button on the second try. Events have not been disabled.
    Any ideas?

  9. #9
    Registered User
    Join Date
    01-24-2017
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    6

    Re: How to disable "X" for closing workbook and force use of button

    Thank you for your reply. I just tried the code and it still allows the user to exit using the close "X" button on the second try. Events have not been disabled.
    Any ideas?

  10. #10
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,049

    Re: How to disable "X" for closing workbook and force use of button

    Midfielder welcome to the forum

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ 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] Force "Save As" in Prompt Before Close - X Button
    By RodrigoTomaz in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-06-2013, 02:00 PM
  2. Create a Command Button to "Save As" and "Close" an Excel Workbook
    By thedunna in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-26-2013, 05:38 PM
  3. How to change a Command Button caption from "Enable" to "Disable"?
    By Infinity in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-22-2007, 12:14 AM
  4. Replies: 0
    Last Post: 11-08-2005, 10:10 AM
  5. [SOLVED] Disable the "X" close button in an excel application
    By Tempy in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 04-19-2005, 11:06 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