Removing double quotes in File SaveAs in Word

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
    With doc
        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
    End With
    FileName = sComposedFilename
End Function

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!

Larry
JWK801Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
I think you need to explain this in a bit more detail. You use an off-stage function (GetFieldValue) so, I have modified the code as below. The modifed function returns

C:\Documents and Settings\Deb\Desktop\FULLNAME FILENAME 100408


Where do you see the quotes?


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
    With doc
        Dim sFullname$, sFileName$, sDoctype$
        sFullname = "FULLNAME" 'GetFieldValue(doc, "FULLNAME") 'fullname
        sFileName = "FILENAME" 'GetFieldValue(doc, "FILENAME") 'filename
        sDoctype = "DOCTYPE" 'GetFieldValue(doc, "DOCTYPE") 'doctype
        sComposedFilename = sFullname & " " & sFileName & " " & Format(Now(), "yymmdd")
        .BuiltInDocumentProperties(wdPropertyTitle) = sDoctype
        .BuiltInDocumentProperties(wdPropertySubject) = sFullname
        .BuiltInDocumentProperties(wdPropertyComments) = sComposedFilename
        sComposedFilename = MyFilePath & "\" & sComposedFilename
    End With
    FileName = sComposedFilename
End Function

Open in new window

0
dotofficeCommented:
CorrectFileName = replace(Filename(doc),chr(34),"")
0
GrahamSkanRetiredCommented:
I have now tried using your function in a SaveAs routine in Word 2007 & still don't see any quotes in the dialogue. Which version of Word are you using? Does the dialogue actually try to save with the quotes as part of the file name or are they display only?
Sub SaveAsDialog()
    Dim dlg As Dialog
    
    Set dlg = Dialogs(wdDialogFileSaveAs)
    dlg.Name = FileName(ActiveDocument)
    dlg.Show
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

JWK801Author Commented:
@dotoffice: tried that one already but it didn't work.

@grahamskan: the doubles qoutes comes in during display. I'm using Word 2007. I think the issue is very specific for some reasons. Let me do further checking guys.

Thanks for your suggestions, it really means a lot.

Larry
0
bromy2004Commented:
If you supply your function "GetFieldValue" we could find out where the double quotes are coming from
0
JWK801Author Commented:
You can actually get rid of the GetfieldValue. Just try this one: sComposedFilename = sFullname & " " & sFileName & " " & Format(Now(), "yymmdd")

Just supply some value of the variables and let sComposedFilename be the value to pass during SaveAsDialog.

On our case, the filename comes enclosed with double quotes.


Thanks for your help guys.
0
GrahamSkanRetiredCommented:
Can we see the code whre you call the SaveAsDialog, please?
0
JWK801Author Commented:
Sir Graham,

Just this one:

Sub SaveAsDialog()
    Dim dlg As Dialog
   
    Set dlg = Dialogs(wdDialogFileSaveAs)
    dlg.Name = FileName(ActiveDocument)
    dlg.Show
End Sub

Unfortunately, I recently discovered that the GetFieldValue (this value is a merge field coming from MS Dynamics CRM) is the one causing the double quotes.

Forgive me if I may ask this, do you have other option in retrieving values for merge fields?

With sincere thanks,

Larry
0
JWK801Author Commented:
The solution is that the Getfieldvalue is the one causing the double quotes once concatenated with a space in between.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.