When we concatenate a space " " in a filename, it adds double quotes when the filesaveas dialog is displayed.
Original filename: Smith, JohnLetter of Instruction
From the original filename we just want to add double qoutes between "John" and "Letter". But we must make sure that double quotes should not display in the FileSaveAsDialog. The output we want: Smith, John Letter of Instruction but currently the output is : "Smith, John Letter of Instruction"
Public Function FileName(doc As Document) As String
Dim sComposedFilename As Variant
Dim MyFilePath As String
MyFilePath = "C:\Documents and Settings\Deb\Desktop" 'Change to your desired path
Dim sFullname$, sFileName$, sDoctype$
sFullname = GetFieldValue(doc, "FULLNAME") 'fullname
sFileName = GetFieldValue(doc, "FILENAME") 'filename
sDoctype = GetFieldValue(doc, "DOCTYPE") 'doctype
sComposedFilename = sFullname & " " & sFileName & " " & Format(Now(), "yymmdd")
.BuiltInDocumentProperties(wdPropertyTitle) = sDoctype
.BuiltInDocumentProperties(wdPropertySubject) = sFullname
.BuiltInDocumentProperties(wdPropertyComments) = sComposedFilename
sComposedFilename = MyFilePath & "\" & sComposedFilename
FileName = sComposedFilename
The above snipplet of VBA word should work OK, unfortunately when the filedialog comes out the filename is enclose with double quotes. This is because we concatenated a white space in between variables. But if we remove it, double quotes are not displayed.
Can someone explain and give us another option perhaps?
Thanks a lot in advance!