rabbitoh


Does anyone know how to disable the X on the top right corner of a UserForm so that when a user clicks on it to close the form, they get a message saying "Please use the Exit button" (which is a macro button on the form itself)



Re: Disabling the X (close) button on a UserForm

magicalclick


I don't know the answer, but I like the X since this is good for developer. I can press X and add more code. Usually my cancel button close the whole workbook, so, I can't use that button myself.




Re: Disabling the X (close) button on a UserForm

Andy Pope

Hi,

One way

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)

If CloseMode = vbFormControlMenu Then
MsgBox "Please use Close Button"
Cancel = True
Exit Sub
End If

End Sub







Re: Disabling the X (close) button on a UserForm

Jon Peltier

Since the user clicks the X to close, why not let them Otherwise they won't like your software..

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

End Sub

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





Re: Disabling the X (close) button on a UserForm

rabbitoh

Brilliant, thank you for that.




Re: Disabling the X (close) button on a UserForm

rabbitoh

Thanks for your answer Jon. The question you have posed (why not let them) has caused me to rethink my outcome. Why I wanted the message box was to avoid having the user end up on the active sheet after closing the form. By having the message it would have directed them to choose one of the form button options. I now see that I can have the Close (X) button simply change to another worksheet (a default worksheet) upon clicking so the message box is perhaps unnecessary.