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 (wdPropert yTitle) = sDoctype
.BuiltInDocumentProperties (wdPropert ySubject) = sFullname
.BuiltInDocumentProperties (wdPropert yComments) = 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
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
.BuiltInDocumentProperties
.BuiltInDocumentProperties
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
CorrectFileName = replace(Filename(doc),chr( 34),"")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
@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
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.
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?
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
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
ASKER
The solution is that the Getfieldvalue is the one causing the double quotes once concatenated with a space in between.
C:\Documents and Settings\Deb\Desktop\FULLN
Where do you see the quotes?
Open in new window