Hyperlinks Collection Object

Description

Represents the collection of Hyperlink objects in a document, range, or selection.

Using the Hyperlinks Collection

Use the Hyperlinks property to return the Hyperlinks collection. The following example checks all the hyperlinks in document one for a link that contains the word "Microsoft" in the address. If a hyperlink is found, it's activated with the Follow method.

For Each hLink In Documents(1).Hyperlinks
    If InStr(hLink.Address, "Microsoft") <> 0 Then
        hLink.Follow
        Exit For
    End If
Next hLink
Use the Add method to create a hyperlink and add it to the Hyperlinks collection. The following example creates a new hyperlink to the MSN Web site.

ActiveDocument.Hyperlinks.Add Address:="http://www.msn.com/", _
    Anchor:=Selection.Range
Use Hyperlinks(index), where index is the index number, to return a single Hyperlink object in a document, range, or selection. The following example activates the first hyperlink in the selection.

If Selection.HyperLinks.Count >= 1 Then
    Selection.HyperLinks(1).Follow
End If
Remarks

The Count property for this collection in a document returns the number of items in the main story only. To count items in other stories use the collection with the Range object.

Properties

Application property, Count property, Creator property, Parent property.

Methods

Add method (Hyperlinks collection), Item method.