Is it possible pop up a msgbox before closing a userform by clicking the X button, so that you have the option to cancel this action?
Printable View
Is it possible pop up a msgbox before closing a userform by clicking the X button, so that you have the option to cancel this action?
You could always disable it and then create you're own close button on your form that you can freely handle...
Click here for link for code to disable the 'x' close button
I didn't try all options but test the CloseMode param for the following values:Code:Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If MsgBox("Really close?", vbYesNo + vbQuestion, "Close Userform") = vbNo Then
Cancel = True
End If
End Sub
'excel 2007
Code:vbFormControlMenu -- 0 -- The user chose the Close command from the Control menu on the form.
vbFormCode -- 1 -- The Unload statement is invoked from code.
vbAppWindows -- 2 -- The current Microsoft Windows operating environment session is ending.
vbAppTaskManager -- 3 -- The Windows Task Manager is closing the application.