What is the syntax to prevent closing userform using X Corner

Insert this code into userform code just like you would any procedure:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
   If CloseMode=0 Then
      Cancel=true
      MsgBox “Please use the exit button instead”, vbCritical
   End If
End Sub
Advertisements