Hi Cor,
Well, not quite. That would display the message whenever the user closes the
userform, regardless of how they did it. I'd find that annoying if I
actually had clicked OK or Cancel. What you want is this:
Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Use the OK or Cancel button to close this form"
End If
End Sub
An alternative would be to assume that the X button should be the equivalent
of the Cancel button, and just do it:
Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
btnCancel_Click
End If
End Sub
If you've renamed the Cancel button to something other than btnCancel, alter
this as necessary.