code for close button
'Place this code in a Module
Sub S$howForm()      
End Sub 

'Place this code in a UserForm with one Command Button named CommandButton1.

Option Explicit 
Private Sub CommandButton1_Click()      
    Unload Me      
End Sub 

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)      
    If CloseMode = 0 Then 
        Cancel = True 
        MsgBox The X is disabled, please use a button on the form., vbCritical 
    End If      
End Sub