Hyperlinks object (Publisher)
Represents the collection of Hyperlink objects in a text range.
Remarks
Use the TextRange.Hyperlinks property to return the Hyperlinks collection.
Use the Add method to create a hyperlink and add it to the Hyperlinks collection.
Use Hyperlinks (index), where index is the index number, to return a single Hyperlink object in a publication, range, or selection.
The Count property for this collection returns the number of hyperlinks in the specified shape or selection only.
Example
The following example deletes all text hyperlinks in the active publication that contain the word Tailspin in the address.
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
The following example creates a new hyperlink to the specified website.
Sub AddHyperlink()
Selection.TextRange.Hyperlinks.Add Text:=Selection.TextRange, _
Address:="https://www.tailspintoys.com/"
End Sub
This example displays the address for the first hyperlink if the specified selection contains hyperlinks.
Sub DisplayHyperlinkAddress()
With Selection.TextRange.Hyperlinks
If .Count > 0 Then _
MsgBox .Item(1).Address
End With
End Sub
Methods
Properties
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.