This documentation is archived and is not being maintained.

Hyperlinks Collection

Hyperlinks Collection
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
TextRange
Aa662002.parchild(en-us,office.10).gifHyperlinks
Aa662002.space(en-us,office.10).gifAa662002.parchild(en-us,office.10).gifHyperlink

Represents the collection of Hyperlink objects in a text range.

Using the Hyperlinks Collection

Use the Hyperlinks property to return the Hyperlinks collection. The following example deletes all text hyperlinks in the active publication that contain the word "Microsoft" 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, "microsoft") <> 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 Microsoft Web site.

Sub AddHyperlink()
    Selection.TextRange.Hyperlinks.Add Text:=Selection.TextRange, _
	Address:="http://www.microsoft.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.

Show: