Disable Close X Button On Excel Application

C

Celtic_Avenger

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
 
J

Jim Rech

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

Bob Phillips

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top