Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Stopping users from "x-ing" out of a workbook

  Asked By: Maddison    Date: Aug 10    Category: MS Office    Views: 481
  

I am trying to force users to exit with a button that I've placed on a
worksheet. I would like to disable the X button on the Window-pane, but
I can't quite figure out how. I've accomplished this in Userforms using
this logic:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)

If CloseMode = vbFormControlMenu Then Cancel = True

End Sub

But I can't quite find the equivalent for a workbook. Excel doesn't
seem to recognize a Workbook_QueryClose event. And I have been unable
to come up with an equivalent for CloseMode or vbFormControlMenu for
that will return any values in the Workbook_BeforeClose event.

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Skye Hughes     Answered On: Aug 10

You are close, try this below

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)
If CloseMode = VbQueryClose.vbFormControlMenu Then
Cancel = True
End If
End Sub

 
Answer #2    Answered By: Funsani Chalthoum     Answered On: Aug 10

It works for UserForms, but I can't get the same behavior
for the Worksheet window. I am trying to prevent users  from "x-ing" out of my
workbook. I have created a series of "exit" buttons that I want them to use,
and I don't want anyone to accidentally go around them and close out the
workbook by x-ing out.

 
Answer #3    Answered By: Randall Franklin     Answered On: Aug 10

This in the Thisworkbook code module:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If OkToClose Then Cancel = True
End Sub

OkToClose is a boolean global variable which you create and is set to
False most of the time (especially on opening the workbook!). The only
time it's set to True is in the code for your exit  buttons.

 
Didn't find what you were looking for? Find more on Stopping users from "x-ing" out of a workbook Or get search suggestion and latest updates.




Tagged: