View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Rech Jim Rech is offline
external usenet poster
 
Posts: 2,718
Default 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



--
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