Disable X (quit) Button

  • Hi,

    I'm sure there is a way to disable the 'X' (quit) button in the top right-hand corner of the EXcel application (not the 'X' for individual workbooks), or the hook the quit event so that I can run code that shut down the application cleanly? I'm sure a Windows API call is involved but do not know enough about that side of programming to know for sure.


  • Re: Disable X (quit) Button

    You can do it with API, although I generally wouldnt recommend it.
    Fortunately this will only effect the current application and does not persist between sessions.

  • Re: Disable X (quit) Button

    Thanks Insomniac,

    Although you do not recommend it. It works fine.

    I know that you can trap application-level events using a class module and creating an application object "with events". However, there is not Quit event available in the drop-down for events. Is there anyway of trapping the quit event?

    Thank again,

  • Re: Disable X (quit) Button

    There is no Application.Quit event, but you can trap WorkbookBeforeClose at an Application level.

    Private Sub XlApp_WorkbookBeforeClose(Byval Wb As Workbook, Cancel As Boolean) 
    MsgBox Wb.Name & " is Closing"
    End Sub
  • Re: Disable X (quit) Button

    You are likely to cause yourself unnecessary troubles with this. If it fails on a user I hope you are ready for any flak they throw at you - I know how I feel when an application messes up my settings

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!