Many times I’ve wrote applications, where top right X button had to be disabled. Code has been borrowed from Johna Walkenbach.
When user clicks UserForm “X” button then Msgbox appears. Code for Msgbox:
MsgBox "To close this window please click START lub CLOSE.", vbInformation, "ERRROR..."
Please notice that MsgBox says that in UserForm there are two more button such as START and CLOSE. These buttons have to be added to UserForm with code to close Userform this is Unload Me.
Following code has to pasted in UserForm area, in UserForm area where we want to block right top X button:
Private Sub UserForm_QueryClose _ (Cancel As Integer, CloseMode As Integer) If CloseMode = vbFormControlMenu Then MsgBox "To close this window please click START lub CLOSE.", vbInformation, "ERRROR..." Cancel = True End If End Sub