+ Reply to Thread
Results 1 to 12 of 12

Disable excel's "Close" button (red X) in workbook for more than 1 click

  1. #1
    Registered User
    Join Date
    07-26-2018
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    6

    Disable excel's "Close" button (red X) in workbook for more than 1 click

    Hi all

    I have seen a few threads on this topic and have applied the basic below code in to the object "ThisWorkbook". It unfortunately only works for the first click and once dismissing the message box has occurred the close (x) button can then be pushed and operates as normal.

    I would like to completely disable closing the workbook in this manner and rather direct the user to a button to close the workbook.

    Here is my code:
    Please Login or Register  to view this content.
    The interesting thing is that it will work for infinite clicks only if I have 2 workbooks open with both of them having the above code in the "ThisWorkbook" object?!
    Please note I want this to prevent a close of the workbook and NOT A USER FORM.

    Thanks in advance
    Last edited by AliGW; 07-27-2018 at 06:07 AM. Reason: Code tags added.

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

    Re: Disable excel's "Close" button (red X) in workbook for more than 1 click

    Try this code
    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

  3. #3
    Registered User
    Join Date
    07-26-2018
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    6

    Re: Disable excel's "Close" button (red X) in workbook for more than 1 click

    Hi YasserKhalil

    It unfortunately still only works for the first click. I have seen similar reply to the one you gave elsewhere and it didn't work either.

    Any other suggestions?

    Thanks

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

    Re: Disable excel's "Close" button (red X) in workbook for more than 1 click

    What do you mean with the first click? It is supposed that it will disable x close button of the application then you can use a button to close and save .. If you used a button the application will be closed
    I tried to click more than once and it doesn't respond and I could only close using the button on the worksheet

  5. #5
    Registered User
    Join Date
    07-26-2018
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    6

    Re: Disable excel's "Close" button (red X) in workbook for more than 1 click

    When I say the "first click" I mean that when I go and click close in the top right hand corner for the first time I get the message box pop up as expected. If I click ok on the message box and then go and try close the workbook again it then closes like it normally would. I don't get the message box appear again. So it only ever functions correctly for the first iteration and then it no longer works and I can close the workbook as usual with the close button in the top right hand corner.

    I have assigned your CloseMe sub to a button which does close the workbook.
    Is it possible to post a video so i can show you how?

    Regards

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

    Re: Disable excel's "Close" button (red X) in workbook for more than 1 click

    This doesn't happen for me .. Try this attachment
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    07-26-2018
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    6

    Re: Disable excel's "Close" button (red X) in workbook for more than 1 click

    On my machine your file does the same thing for me as my code and only works on the first attempt. After that it closes as normal. Do you know of any settings that may need to be changed to prevent this happening because it must be something other than the macro.

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

    Re: Disable excel's "Close" button (red X) in workbook for more than 1 click

    I am using 2016 version and no specific settings for that .. Waiting for other experts

  9. #9
    Registered User
    Join Date
    07-26-2018
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    6

    Re: Disable excel's "Close" button (red X) in workbook for more than 1 click

    I am also using 2016.

    I tried it out after remote desktopping in to a server running excel 2010 and it worked correctly there. I also tried it through VDI in to another portal running 2016 and it only worked for 1 click there.

    So something is strange.

    Im using a surface pro laptop

  10. #10
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,026

    Re: Disable excel's "Close" button (red X) in workbook for more than 1 click

    I can't replicate this. Would an alternative be to allow the BeforeClose event to share whatever actions the button performs?

  11. #11
    Registered User
    Join Date
    07-26-2018
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    6

    Re: Disable excel's "Close" button (red X) in workbook for more than 1 click

    Hi ByteMarks

    Even writting the code as a stand alone and not attached to any button doesnt work. Ive checked the code on other computers and they are all fine. It is the surface pro that seems to be the issue which others seem to have noted on other forums.

    Regards

  12. #12
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: Disable excel's "Close" button (red X) in workbook for more than 1 click

    Looks like this issue has been encountered a number of times on other forums without solution (other than obviously just using the excel version/computer that works!).

    maybe you should revisit why you want to use the before_close and maybe there is another way of looking at the problem, assuming this is a significant issue on your side.
    If you want something done right... find a forum and ask an online expert.

    Time flies like an arrow. Fruit flies like a banana.

+ 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] How to disable "X" for closing workbook and force use of button
    By MarkBridgeman69 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-25-2017, 12:35 AM
  2. vba code to disable only close button and close through a button in Excel workbook
    By atif_ar in forum Excel Programming / VBA / Macros
    Replies: 47
    Last Post: 11-23-2014, 02:41 PM
  3. 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
  4. [SOLVED] Need a save and close macro that does not care if the "edit workbook" button has be clcked
    By rt3 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-22-2013, 08:42 AM
  5. Replies: 0
    Last Post: 04-09-2013, 04:29 AM
  6. [SOLVED] Disable "Right Click" ... or any ability to "cut", "insert", etc.
    By jonvanwyk in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-23-2011, 09:26 AM
  7. 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

Tags for this Thread

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