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 how I can prevent it from happening?
And Yes, I know this is MRExcel, not MRWord ... I'm just hoping that someone here can shed some light on this, since you're the best group of VBA experts around!
Dim docname As String, formatting As String
formatting = " \a \r \* MERGEFORMAT"
docname = Chr(34) & "C:Mydocuments\test.doc" & Chr(34) ' enclose docname in double quotes
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
And Yes, I know this is MRExcel, not MRWord ... I'm just hoping that someone here can shed some light on this, since you're the best group of VBA experts around!
Dim docname As String, formatting As String
formatting = " \a \r \* MERGEFORMAT"
docname = Chr(34) & "C:Mydocuments\test.doc" & Chr(34) ' enclose docname in double quotes
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