![]() |
Disable Close X Button On Excel Application
Hi Peeps. I have used the following code to disable the X button on Userforms but is this possible with the main Excel Application X button? If s what do I need to change and where do I need to put the code? Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode A Integer) If CloseMode < vbFormCode Then MsgBox "Please Note!" & Chr(13) & Chr(13) & "The Close Button Has Bee Disabled To Ensure No Loss Of Data." & Chr(13) & Chr(13) & "Please Us The Save And Close Button At The Bottom Of This Menu!", _ vbOKOnly, "IMPORTANT!" Cancel = True End If End Sub Hope someone can help! Celtic_Avenger :confused: :confused: :confused: :confused: :confused -- Celtic_Avenge ----------------------------------------------------------------------- Celtic_Avenger's Profile: http://www.excelforum.com/member.php...fo&userid=1410 View this thread: http://www.excelforum.com/showthread.php?threadid=27397 |
Disable Close X Button On Excel Application
You can prevent your workbook from being closed with code like this:
Private Sub Workbook_BeforeClose(Cancel As Boolean) If SomeCondition Then Cancel = True End Sub If your workbook is being closed indirectly by closing Excel this code blocks Excel's closing. -- Jim Rech Excel MVP "Celtic_Avenger" wrote in message ... Hi Peeps. I have used the following code to disable the X button on Userforms, but is this possible with the main Excel Application X button? If so what do I need to change and where do I need to put the code? Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If CloseMode < vbFormCode Then MsgBox "Please Note!" & Chr(13) & Chr(13) & "The Close Button Has Been Disabled To Ensure No Loss Of Data." & Chr(13) & Chr(13) & "Please Use The Save And Close Button At The Bottom Of This Menu!", _ vbOKOnly, "IMPORTANT!" Cancel = True End If End Sub Hope someone can help! Celtic_Avenger :confused: :confused: :confused: :confused: :confused: -- Celtic_Avenger ------------------------------------------------------------------------ Celtic_Avenger's Profile: http://www.excelforum.com/member.php...o&userid=14101 View this thread: http://www.excelforum.com/showthread...hreadid=273978 |
Disable Close X Button On Excel Application
There is no simple way in Excel, and removing a windows function might not
be appreciated. What you could do is to change the BeforeClose workbook event like so Private Sub Workbook_BeforeClose(Cancel As Boolean) Cancel=true End Sub which will stop Excel closing that workbook, thus won't shutdown. Problem is, you can't close that workbook from code either. You could add a global Boolean to test for it, and if you want to shutdown or close this workbook, set it to True Private Sub Workbook_BeforeClose(Cancel As Boolean) If Not CloseOK Then Cancel=true End If End Sub although this does leave you open to Excel being closed if you shut this workbook in code. Removing the X takes API calls. -- HTH RP "Celtic_Avenger" wrote in message ... Hi Peeps. I have used the following code to disable the X button on Userforms, but is this possible with the main Excel Application X button? If so what do I need to change and where do I need to put the code? Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If CloseMode < vbFormCode Then MsgBox "Please Note!" & Chr(13) & Chr(13) & "The Close Button Has Been Disabled To Ensure No Loss Of Data." & Chr(13) & Chr(13) & "Please Use The Save And Close Button At The Bottom Of This Menu!", _ vbOKOnly, "IMPORTANT!" Cancel = True End If End Sub Hope someone can help! Celtic_Avenger :confused: :confused: :confused: :confused: :confused: -- Celtic_Avenger ------------------------------------------------------------------------ Celtic_Avenger's Profile: http://www.excelforum.com/member.php...o&userid=14101 View this thread: http://www.excelforum.com/showthread...hreadid=273978 |
All times are GMT +1. The time now is 12:15 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com