J
johnnykunst
I have the following code, all of which works fine when run from the VBA editor:
Private Sub CommandButton1_Click()
If ActiveDocument.FormFields("nameDD").Result = "ENTER NAME" Then
MsgBox "You forgot to fill in your name. This field MUST be filled in before you can save the document"
Exit Sub
End If
Call RunSpellcheck
Dim pStr As String
pStr = "C:\Users\John\Desktop\" 'Your directory
pStr = pStr + ActiveDocument.FormFields("nameDD").Result
pStr = pStr + " "
pStr = pStr + ActiveDocument.FormFields("classificationDD").Result
pStr = pStr + " "
pStr = pStr + ActiveDocument.FormFields("wardDD").Result
pStr = pStr + " .docx"
ActiveDocument.SaveAs FileName:=pStr
Dim sCode As String
MsgBox "Your Intelligence report was saved to the central WINTEL inbox for processing & emailing. No further action is required; it is now safe to close the document"
End Sub
However, this code is assigned to a button on my Word template and when it is fired from this button the following section does not work:
If ActiveDocument.FormFields("nameDD").Result = "ENTER NAME" Then
MsgBox "You forgot to fill in your name. This field MUST be filled in before you can save the document"
Exit Sub
End If
The section is to check that a field has been filled in, and if it hasn't, to stop the macro, if it has, to continue with the rest of the macro.
Private Sub CommandButton1_Click()
If ActiveDocument.FormFields("nameDD").Result = "ENTER NAME" Then
MsgBox "You forgot to fill in your name. This field MUST be filled in before you can save the document"
Exit Sub
End If
Call RunSpellcheck
Dim pStr As String
pStr = "C:\Users\John\Desktop\" 'Your directory
pStr = pStr + ActiveDocument.FormFields("nameDD").Result
pStr = pStr + " "
pStr = pStr + ActiveDocument.FormFields("classificationDD").Result
pStr = pStr + " "
pStr = pStr + ActiveDocument.FormFields("wardDD").Result
pStr = pStr + " .docx"
ActiveDocument.SaveAs FileName:=pStr
Dim sCode As String
MsgBox "Your Intelligence report was saved to the central WINTEL inbox for processing & emailing. No further action is required; it is now safe to close the document"
End Sub
However, this code is assigned to a button on my Word template and when it is fired from this button the following section does not work:
If ActiveDocument.FormFields("nameDD").Result = "ENTER NAME" Then
MsgBox "You forgot to fill in your name. This field MUST be filled in before you can save the document"
Exit Sub
End If
The section is to check that a field has been filled in, and if it hasn't, to stop the macro, if it has, to continue with the rest of the macro.