E
Ed from AZ
In Word 2007, I'm trying to add a hyperlink, but it keeps crashing
Word. What I'm trying to accomplish is to iterate through my
Favorites folder and write these as hyperlinks into a Word document.
I found some code on the MSDN Library site that uses the FSO to
recursively iterate through a folder and write the file path to
everything into an FSO Dictionary, then reads it all out.
When it read out with Debug.Print, all worked fine. Then I added a
few things to write these into the doc as hyperlinks, and it crashes
every time. Here's the crash point:
strLink = varItem
Set rng = doc.Paragraphs(doc.Paragraphs.Count).Range
doc.Hyperlinks.Add Anchor:=rng, _
Address:=strLink, TextToDisplay:=strName
doc.Content.InsertAfter vbCrLf
varItem is from
For Each varItem In dctDict
where dctDict is the FSO dictionary.
When the crash occurs ("We're sorry but Word has encountered a problem
and must shut down. Would you like to recover this and send an error
report?"), the Hyperlinks.Add line is in yellow. When I open the
recovered document, the hyperlink is indeed in the document, with the
correct text displayed and the correct address; the vbCrLf is not
added.
Can anyone shed any light here, please?
Ed
Word. What I'm trying to accomplish is to iterate through my
Favorites folder and write these as hyperlinks into a Word document.
I found some code on the MSDN Library site that uses the FSO to
recursively iterate through a folder and write the file path to
everything into an FSO Dictionary, then reads it all out.
When it read out with Debug.Print, all worked fine. Then I added a
few things to write these into the doc as hyperlinks, and it crashes
every time. Here's the crash point:
strLink = varItem
Set rng = doc.Paragraphs(doc.Paragraphs.Count).Range
doc.Hyperlinks.Add Anchor:=rng, _
Address:=strLink, TextToDisplay:=strName
doc.Content.InsertAfter vbCrLf
varItem is from
For Each varItem In dctDict
where dctDict is the FSO dictionary.
When the crash occurs ("We're sorry but Word has encountered a problem
and must shut down. Would you like to recover this and send an error
report?"), the Hyperlinks.Add line is in yellow. When I open the
recovered document, the hyperlink is indeed in the document, with the
correct text displayed and the correct address; the vbCrLf is not
added.
Can anyone shed any light here, please?
Ed