i know this can be done if you are using forms

and the code to do this looks like this

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "type your message here if the user presses the X button"
End If
End Sub

I hope that helps.