View Full Version : Solved: Disable "X" Button on ActiveWorkBook
stanl
06-12-2006, 03:00 AM
I can use the Application.Hwnd property and the RemoveMenu API to disable the Close [X] button on an instance of Excel.
Additionally I can issue Application.CommandBars("File").Enabled = False to disable the File Menu.
I then load a template for data entry and assume for all intensive purposes that the user cannot close Excel, or perform file I/O. However, the user can still click the X on the ActiveWorkbook and close the template. My question: is their a way to disable the Close Button on the Activeworkbook? Stan
Justinlabenne
06-12-2006, 05:44 AM
Sure,
Bob Phillips
06-12-2006, 06:13 AM
This is a poor programming technique IMO, as you are stopping the user from doing things that other workbooks permit. I would suggest that it is better to interecept the BeforeClose event, and do whatever you want to do there.
stanl
06-12-2006, 06:49 AM
Justin;
Your code disables the X on the Application, not the ActiveWorkbook (see attached jpg - I want to disable X on the RemoveX child window, not the Excel main window).
Stan
stanl
06-12-2006, 06:51 AM
This is a poor programming technique IMO, as you are stopping the user from doing things that other workbooks permit. I would suggest that it is better to interecept the BeforeClose event, and do whatever you want to do there.
XLD;
While I agree in general, in this particular application the user never runs Excel - they run a .wsc that opens the Excel Object then the template file - there is no macro code in the template, and I don't want any. The user can enter data, but must click on the floating toolbar [created by the .wsc] to save and close the workbook and Excel object. See attached jpg - it is a test template, not the real thing.
stanl
06-12-2006, 11:13 AM
I figured it out. Needed to 'hijack' the WorkBookBeforeClose() event and set Cancel=True. But then I needed to release the event after my floating toolbutton is pressed so that Excel Object could be closed normally.
Stan
Justinlabenne
06-12-2006, 06:21 PM
Glad you figured it out. Sorry for misreading......to remove the window close:
Option Explicit
Public Sub RemoveWindowX()
ActiveWorkbook.Protect , , True
End Sub
Public Sub RestoreWindowX()
ActiveWorkbook.Protect , , False
End Sub
Bob Phillips
06-13-2006, 02:11 AM
XLD;
While I agree in general, in this particular application the user never runs Excel - they run a .wsc that opens the Excel Object then the template file - there is no macro code in the template, and I don't want any. The user can enter data, but must click on the floating toolbar [created by the .wsc] to save and close the workbook and Excel object. See attached jpg - it is a test template, not the real thing.
and yet you plaster the Excel icon all over it?
stanl
06-13-2006, 10:41 AM
and yet you plaster the Excel icon all over it?
To repeat: "it is a test template, not the real thing"
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.