There are some strange anomalies in your code, which I assume you are running from the document itself? That being the case there is no need to setup a new version of Word to save the file, and if not then the rest of the code will need to be addressed.
Given the propensity for users to enter the wrong things in fields, you need to ensure that the fields are completed and that what is entered does not include illegal filename characters. The following will address those concerns with a code sample that you can find on my web site.
The code will not overwrite the original DOCM format file and saving as DOCX will strip the macros.
Sub SavePSDU()
Dim strName As String, strDate As String
Dim strLN As String, strFN As String, strID As String
Dim oFF As FormField
For Each oFF In ActiveDocument.FormFields
If oFF.Name = "Part_LN" Then
strLN = oFF.Result
If strLN = "" Then
MsgBox "Complete the field " & oFF.Name
oFF.Select
GoTo lbl_Exit
End If
End If
If oFF.Name = "Part_FN" Then
strFN = oFF.Result
If strFN = "" Then
MsgBox "Complete the field " & oFF.Name
oFF.Select
GoTo lbl_Exit
End If
End If
If oFF.Name = "Part_ID" Then
strID = oFF.Result
If strID = "" Then
MsgBox "Complete the field " & oFF.Name
oFF.Select
GoTo lbl_Exit
End If
End If
Next oFF
strName = strLN & "." & strFN & "." & strID & ".PSDU"
strDate = Format(Now(), "yyyy-mm-dd")
strName = strName & "-" & strDate & ".docx"
strName = CleanFileName(strName, ".docx")
strName = "\\NetworkShare\Data Log Files\" & strName
'Debug.Print strName
ActiveDocument.SaveAs2 FileName:=strName, FileFormat:=wdFormatXMLDocument
lbl_Exit:
Exit Sub
End Sub
Private Function CleanFileName(strFilename As String, strExtension As String) As String
'Graham Mayor
'A function to ensure there are no illegal filename
'characters in a string to be used as a filename
'strFilename is the filename to check
'strExtension is the extension of the file
Dim arrInvalid() As String
Dim vfName As Variant
Dim lng_Name As Long
Dim lng_Ext As Long
Dim lngIndex As Long
'Ensure there is no period included with the extension
strExtension = Replace(strExtension, Chr(46), "")
'Record the length of the extension
lng_Ext = Len(strExtension)
'Remove the path from the filename if present
If InStr(1, strFilename, Chr(92)) > 0 Then
vfName = Split(strFilename, Chr(92))
CleanFileName = vfName(UBound(vfName))
Else
CleanFileName = strFilename
End If
'Remove the extension from the filename if present
If Right(CleanFileName, lng_Ext + 1) = "." & strExtension Then
CleanFileName = Left(CleanFileName, InStrRev(CleanFileName, Chr(46)) - 1)
End If
'Define illegal characters (by ASCII CharNum)
arrInvalid = Split("9|10|11|13|34|42|47|58|60|62|63|92|124", "|")
'Add the extension to the filename
CleanFileName = CleanFileName & Chr(46) & strExtension
'Remove any illegal filename characters
For lngIndex = 0 To UBound(arrInvalid)
CleanFileName = Replace(CleanFileName, Chr(arrInvalid(lngIndex)), Chr(95))
Next lngIndex
lbl_Exit:
Exit Function
End Function