嵌入Web链接的问题

时间:2013-10-29 15:14:38

标签: ms-word word-vba

我在vba中有一个带有Web链接的字符串。但是,当字符串显示在Microsoft Word页面上时。文本被包装并且链接被破坏。如何确保VBA知道链接的开始和停止位置?

字符串如下所示:

Dim My_MSG As String 
My_MSG = "Full company list can be found at finance.yahoo.com/blogs/hot-stock-minute/… by yahoo' by yourclients."

当在字表中填充此字符串时,链接无法识别完整链接

1 个答案:

答案 0 :(得分:0)

Word无法自动识别链接。您可以使用Hyperlinks.Add插入超链接。这是一个例子。

Sub AddTextwHyperlink()
   Dim objDoc As Document
   Dim objRng As Range

   Set objDoc = ActiveDocument
   Set objRng = Selection.Range

   'Adds text before link.
   objRng.InsertAfter "Full company list can be found at "

   'Collapses range so that hyperlink will be added after text.
   objRng.Collapse wdCollapseEnd

   'Adds hyperlink and sets the range to start after the hyperlinked text.
   objRng.start = objDoc.Hyperlinks.Add(Anchor:=objRng, Address:="http://finance.yahoo.com/blogs/hot-stock-minute/").Range.End

   'Adds the rest of the text.
   objRng.InsertAfter " by yahoo' by yourclients."

End Sub