Prevent a UserForm from closing when the user clicks the x-button

 2000-02-05    Dialogs    0    47

If you want to prevent a Userform from closing when the user clicks the x-button or close-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.


Leave a comment:

Your comment will only be published after it has been moderated and found spam free.
Your e-mail address will only be used to display your Gravatar.