[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 361
  • Last Modified:

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
0
JWK801
Asked:
JWK801
1 Solution
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now