Results 1 to 12 of 12

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

Threaded View

  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:
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Cancel = True
    MsgBox "Please use the 'Save and Close' button on Sheet 1"
    End Sub
    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.

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. EXCEL: File Doesn't Close With Click On Top Right "x" Button
    By gaikwad.mm@gmail.com in forum Excel Programming / VBA / Macros
    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. [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

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