The macro was originally written to remove spaces and replace them with
underscores using the section
If InStr(1, sFname, " ") <> 0 Then
sFname = Replace(sFname, " ", "_")
End If
and I had deliberatly refrained from adding spaces after the commas as I
assumed from your original post that you didn't want them. So you can start
by losing that bit.
Next the commas are inserted with & Chr(44) &. If you want a space after the
comma you could simply extend each occurrence to
& Chr(44) & CHR(32) &
or
& Chr(44) & " " &
but if you leave
If InStr(1, sFname, " ") <> 0 Then
sFname = Replace(sFname, " ", "_")
End If
those spaces will be replaced with underscores. If you want the underscores
in the field results, you can add them
to the individual field results eg
sValue1 = .FormFields("Project_Name").Result
If InStr(1, sValue1, " ") <> 0 Then
sValue1 = Replace(sValue1, " ", "_")
End If
sValue2 = .FormFields("Document_Title").Result
If InStr(1, sValue2, " ") <> 0 Then
sValue2 = Replace(sValue2, " ", "_")
End If
sValue3 = .FormFields("Document_Type").Result
If InStr(1, sValue3, " ") <> 0 Then
sValue3 = Replace(sValue3, " ", "_")
End If
sValue4 = .FormFields("Version").Result
If InStr(1, sValue4, " ") <> 0 Then
sValue4 = Replace(sValue4, " ", "_")
End If
If you find it simpler to manipulate you can take this a step further and
add the commas and spaces to each string before assembling them in the
sFname string eg
With ActiveDocument
sValue1 = .FormFields("Project_Name").Result
If InStr(1, sValue1, " ") <> 0 Then
'Replace the user entered space with an underscore
sValue1 = Replace(sValue1, " ", "_")
'add the comma and space
sValue1 = sValue1 & Chr(44) & Chr(32)
End If
sValue2 = .FormFields("Document_Title").Result
If InStr(1, sValue2, " ") <> 0 Then
sValue2 = Replace(sValue2, " ", "_")
sValue2 = sValue2 & Chr(44) & Chr(32)
End If
sValue3 = .FormFields("Document_Type").Result
If InStr(1, sValue3, " ") <> 0 Then
sValue3 = Replace(sValue3, " ", "_")
sValue3 = sValue3 & Chr(44) & Chr(32)
End If
sValue4 = .FormFields("Version").Result
If InStr(1, sValue4, " ") <> 0 Then
sValue4 = Replace(sValue4, " ", "_")
sValue4 = sValue4 & Chr(44) & Chr(32)
End If
sFname = sValue1 & sValue2 _
& sValue3 & "Version " & sValue4 & ".doc"
.SaveAs sFname
End With
and if you don't want underscores at all it is even simpler:
With ActiveDocument
sValue1 = .FormFields("Project_Name").Result
sValue1 = sValue1 & Chr(44) & Chr(32)
sValue2 = .FormFields("Document_Title").Result
sValue2 = sValue2 & Chr(44) & Chr(32)
sValue3 = .FormFields("Document_Type").Result
sValue3 = sValue3 & Chr(44) & Chr(32)
sValue4 = .FormFields("Version").Result
sValue4 = sValue4 & Chr(44) & Chr(32)
sFname = sValue1 & sValue2 _
& sValue3 & "Version " & sValue4 & ".doc"
.SaveAs sFname
End With
End Sub
Does that help?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>