Disable Close ('X' in top Right)

thunderfoot

Board Regular
Joined
May 28, 2004
Messages
229
Using EXCEL 2003 and have a Sub Auto_Open() macro routine run when a file is opened (with Macros Enabled) which among other things has a routine that disables Copy/Paste using code :-

Code:
    Application.CommandBars("Edit").Controls("Cut").Enabled = False
    Application.CommandBars("Edit").Controls("Copy").Enabled = False
    Application.CommandBars("Edit").Controls("Paste").Enabled = False
    Application.CommandBars("Edit").Controls("Paste Special...").Enabled = False

Is there any Code I can add to the Sub Auto_Open() macro which will disable the 'X' in the top right corner of the Window displaying the file?
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Have a 'Close' routine which operates from a macro button with the code:-

Code:
    Application.CommandBars("Edit").Controls("Cut").Enabled = True
    Application.CommandBars("Edit").Controls("Copy").Enabled = True
    Application.CommandBars("Edit").Controls("Paste").Enabled = True
    Application.CommandBars("Edit").Controls("Paste Special...").Enabled = True

........... so would hope there's a bit of code to disable the 'X' in the Auto Open routine (1st post) and then a bit of code to go in the above routine to re-enable the 'X'.
 
Last edited:
Upvote 0
Add in the ThisWorkbook module

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cancel = True
End Sub

and add to your close code

Code:
Application.EnableEvents = False
ThisWorkbook.Close
Application.EnableEvents = True
 
Upvote 0

Forum statistics

Threads
1,224,534
Messages
6,179,391
Members
452,909
Latest member
VickiS

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top