Link to home
Start Free TrialLog in
Avatar of JWK801
JWK801

asked on

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
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

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

Avatar of dotoffice
dotoffice

CorrectFileName = replace(Filename(doc),chr(34),"")
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JWK801

ASKER

@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
If you supply your function "GetFieldValue" we could find out where the double quotes are coming from
Avatar of JWK801

ASKER

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.
Can we see the code whre you call the SaveAsDialog, please?
Avatar of JWK801

ASKER

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
Avatar of JWK801

ASKER

The solution is that the Getfieldvalue is the one causing the double quotes once concatenated with a space in between.