Hyperlinks Object (Publisher)

Office 2013 and later

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Represents the collection of Hyperlink objects in a text range.

Use the Hyperlinks property to return the Hyperlinks collection. 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 
 Exit For 
 End If 
 End If 
 End If 
End Sub

Use the Add method to create a hyperlink and add it to the Hyperlinks collection. The following example creates a new hyperlink to the specified Web site.

Sub AddHyperlink() 
 Selection.TextRange.Hyperlinks.Add Text:=Selection.TextRange, _ 
End Sub

Use Hyperlinks(index), where index is the index number, to return a single Hyperlink object in a publication, range, or selection. 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

The Count property for this collection returns the number of hyperlinks in the specified shape or selection only.