Word removing quotes from DocName inserted via VBA ???

From: Adam White (adam.white_at_nospam.sbcglobal.net)
Date: 01/22/05


Date: Sat, 22 Jan 2005 21:55:32 GMT

I have the following vba code which formats a LINK statement which is
then inserted into an existing REF statement (defined by the bookmark)
in a MS Word (2000 SP3) document. The "docname" field contains the
surrounding double quotes when the text is actually inserted into the
bookmark field. But Word seems to take these quotes away if the
actual path/file name does not contain any spaces! It leaves the
quotes alone if there ARE spaces in the name. I'd rather the quotes
stay there regardless. Any idea why this is and/or how I can force
the quotes to remain?

Dim docname As String, formatting As String

formatting = " \a \r \* MERGEFORMAT"
' enclose docname in double quotes
docname = Chr(34) & "C:Mydocuments\test.doc" & Chr(34)

Set BMRange = ActiveDocument.Bookmarks("BM1").Range
Selection.GoTo What:=wdGoToBookmark, Name:="BM1"
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
  Text:= "LINK Excel.Sheet.8 " & docname & " Sheet1!CompanyName" _
  & formatting, PreserveFormatting:=False
ActiveDocument.Bookmarks.Add Range:=BMRange, Name:="BM1"
End Sub