Get rid of the Userform_Terminate and add
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
MsgBox "This is the X Button"
Hide
Tag = 0
Cancel = True
End If
lbl_Exit:
Exit Sub
End Sub
If you have a cancel button on the form then add e.g.
Private Sub CommandButton1_Click()
MsgBox "This is the cancel Button"
Hide
Tag = 0
lbl_Exit:
Exit Sub
End Sub
You could validate the entries so that the user needs to make selections e.g.
Private Sub CommandButton2_Click()
MsgBox "This is the OK Button"
'validate the entries e.g.
If TextBox1.Text = "" Then
MsgBox "Complete TextBox1"
TextBox1.SetFocus
GoTo lbl_Exit
End If
If TextBox2.Text = "" Then
MsgBox "Complete TextBox2"
TextBox1.SetFocus
GoTo lbl_Exit
End If
Hide
Tag = 1
lbl_Exit:
Exit Sub
End Sub
Modify the main code to handle the tags and process the document from the values entered in the userform (rather than do it in the form code)
Sub StartProcess()
Dim oFrm As New UserForm1
If ActiveDocument = ThisDocument Then
MsgBox "You are attempting to process the template." & vbCr & "Create a new document from the template."
GoTo lbl_Exit
End If
With oFrm
.Show
If .Tag = 0 Then
ActiveDocument.Close SaveChanges:=False
End If
'do stuff related to the document and the userform here
Unload oFrm
End With
lbl_Exit:
Set oFrm = Nothing
Exit Sub
End Sub
Ultimately whatever you do some user will screw it up. You just have to plan for everything.