0

我在 vba 中有一个字符串,它有一个网络链接。但是,当字符串显示在 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."

当此字符串填充到单词表中时,该链接无法识别完整的链接

4

1 回答 1

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
于 2013-11-01T21:38:39.630 回答