How to disable the Exit Button of UserForm in Excel?

W

William

Hi Alex

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then Cancel = True
End Sub


--
XL2002
Regards

William

(e-mail address removed)

| How to disable the Exit Button of UserForm in Excel?
 
B

Bob Phillips

Alex,

Adding to this. There are 4 values for CloseMode

vbFormControlMenu 0 The user has chosen the Close command from the
Control menu on the UserForm.
vbFormCode 1 The Unload statement is invoked from code.
vbAppWindows 2 The current Windows operating environment session is
ending.
vbAppTaskManager 3 The Windows Task Manager is closing the
application.


You may only want to trap value 0, but you may also want to trap 2 and 3.
Probably best not to trap 1, else your code won't be able to close it.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
J

Jon Peltier

And since a user typically click the close box when they want out of the form, have
it run the CancelButton_Click code, instead of just hanging there.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______
 

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

Top