Consulting

Results 1 to 5 of 5

Thread: disable close "X" button

  1. #1

    disable close "X" button

    Hello,

    I need your help. I would like to disable the close "X" button requiring the user to click on a control button that I have placed on the spreadsheet. Here is the code I have tried:

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Cancel = True
    MsgBox "Please use the button to close this file"
    End Sub

    The problem is this. This code works fine when the user clicks the close button the first time. If the user clicks the button a second time, the standard Save, Don't Save and Cancel window appears. How can I prevent this from happening? What needs to be changed or added to the above code?
    Thank you in advance for your help!

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    I tried this (code posted at #1) both with the WB in saved and unsaved status, using both the close wb button and close application button and the code repeatedly blocked (cancelled) exiting the wb.

  3. #3
    It only works for me on the first try. Any suggestions?

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    The only thing I can think of is put a Stop above Cancel = True and step through the code. Other than that, by chance is there any code that you are not showing us that disables events?

    Mark

  5. #5

Posting Permissions

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