Disabling A Userform’s Close Button
Category: UserForms | [Item URL]
Every UserForm that you create contains a Close button ("x") in its title bar. Clicking the Close button (or pressing Alt+F4) closes the UserForm.In some cases, you may not want to allow the user to close the UserForm in this manner. There's no easy way to disable the Close button, but a few lines of VBA code will prevent it from being used.
Activate the code module for your UserForm, and enter the following procedure:
Private Sub UserForm_QueryClose _
(Cancel As Integer, CloseMode As Integer)
' Prevents use of the Close button
If CloseMode = vbFormControlMenu Then
MsgBox "Clicking the Close button does not work."
Cancel = True
End If
End Sub
When the user clicks the Close button, a message box appears and the UserForm
remains open.
Excel Tips
Excel has a long history, and it continues to evolve and change. Consequently, the tips provided here do not necessarily apply to all versions of Excel.
In particular, the user interface for Excel 2007 (and later), is vastly different from its predecessors. Therefore, the menu commands listed in older tips, will not correspond to the Excel 2007 (and later) user interface.
All Tips
Browse Tips by Category
Search for Tips
Tip Books
Needs tips? Here are two books, with nothing but tips:
Contains more than 200 useful tips and tricks for Excel | Other Excel 2003 books | Amazon link: John Walkenbach's Favorite Excel Tips & Tricks
Contains more than 200 useful tips and tricks for Excel 2007 | Other Excel 2007 books | Amazon link: John Walkenbach's Favorite Excel 2007 Tips & Tricks
