» Prevent a UserForm from closing when the user clicks the x-button using VBA in Microsoft Excel
VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions
CATEGORY - User Forms, Input boxes in VBA
VERSION - All Microsoft Excel Versions
If you want to prevent a Userform from closing when the user clicks the x-button in the top right corner of the dialog, you can add the macro below to the UserForms code module:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "You can't close the dialog like this!"
End If
End Sub
This will also prevent the dialog to be closed when the user presses Alt+F4 on the keyboard.
Book Store:
Recommended Books:
- How to Use Financial Statements: A Guide to Understanding the Numbers
- Business Plans For Dummies®
- Successful Business Planning in 30 Days: A Step-By-Step Guide for Writing a Business Plan and Starting Your Own Business
- 422 Tax Deductions for Businesses and Self-Employed Individuals : You Get a Raise Every Time You Find a Legitimate Tax Deduction
- Definitive Guide to Excel VBA
- Investments + S&P Card + Powerweb + StockTrak discount coupon
No comments have been submitted.

