Share via


Hyperlinks Object (Publisher)

Represents the collection of Hyperlink objects in a text range.

Example

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 
 hprLink.Delete 
 Exit For 
 End If 
 Next 
 Else 
 shpShape.Hyperlink.Delete 
 End If 
 End If 
 Next 
 Next 
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, _ 
 Address:="http://www.tailspintoys.com/" 
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.