表示 超链接 的集合 在文字范围中的对象。
备注
使用 TextRange.Hyperlinks 属性返回 Hyperlinks 集合。
使用 添加 若要创建超链接,并将其添加到 超链接 集合的方法。
使用 超链接 (索引) ,其中 index 是索引号,以返回发布、范围或所选内容中的单个 超链接 对象。
该集合的 Count 属性只返回指定形状或选定内容中超链接的数量。
示例
下面的示例将删除活动发布中地址中包含单词 Tailspin 的所有文本超链接。
Sub DeleteMSHyperlinks()
Dim pgsPage As Page
Dim shpShape As Shape
Dim hprLink As Hyperlink
For Each pgsPage In ActiveDocument.Pages
For Each shpShape In pgsPage.Shapes
If shpShape.HasTextFrame = msoTrue Then
If shpShape.TextFrame.HasText = msoTrue Then
For Each hprLink In shpShape.TextFrame.TextRange.Hyperlinks
If InStr(hprLink.Address, "tailspin") <> 0 Then
hprLink.Delete
Exit For
End If
Next
Else
shpShape.Hyperlink.Delete
End If
End If
Next
Next
End Sub
以下示例新建指向指定网站的超链接。
Sub AddHyperlink()
Selection.TextRange.Hyperlinks.Add Text:=Selection.TextRange, _
Address:="https://www.tailspintoys.com/"
End Sub
如果指定的选定内容包含超链接,则本示例显示第一个超链接的地址。
Sub DisplayHyperlinkAddress()
With Selection.TextRange.Hyperlinks
If .Count > 0 Then _
MsgBox .Item(1).Address
End With
End Sub
方法
属性
另请参阅
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。