Class Hyperlinks (Excel VBA)
The class Hyperlinks represents the collection of hyperlinks for a worksheet or range. To use a Hyperlinks class variable it first needs to be instantiated, for example
Dim hyps as Hyperlinks
Set hyps = ActiveCell.Hyperlinks
For Each
Here is an example of processing the Hyperlinks items in a collection.
Dim hyp As Hyperlink
For Each hyp In ActiveCell.Hyperlinks
Next hyp
Add
Adds a hyperlink to the specified range or shape.
When you specify the TextToDisplay argument, the text must be a string.
Add (Anchor, Address, SubAddress, ScreenTip, TextToDisplay)
With Worksheets(1)
.Hyperlinks.Add Anchor:=.Range("a5"), _
Address:="https://example.microsoft.com", _
ScreenTip:="Microsoft Web Site", _
TextToDisplay:="Microsoft"
End With
Arguments
The following arguments are required:
Anchor (Shape) - The anchor for the hyperlink. Can be either a Range or Shape object.
Address (String) - The address of the hyperlink.
Optional arguments
The following arguments are optional
SubAddress (String) - The subaddress of the hyperlink.
ScreenTip (String) - The screen tip to be displayed when the mouse pointer is paused over the hyperlink.
TextToDisplay (String) - The text to be displayed for the hyperlink.
Count
Returns a Long value that represents the number of objects in the collection.
Dim lngCount As Long
lngCount = ActiveCell.Hyperlinks.Count
Delete
Deletes the object.
Calling the Delete method on the specified Hyperlinks object is equivalent to using both the Clear Hyperlinks and Clear Formats commands from the Clear drop-down list in the Editing section of the Home tab. Not only hyperlinks will be removed; cell formatting will be removed also. If you only want to remove the hyperlink, see the Range.ClearHyperlinks method.
ActiveCell.Hyperlinks.Delete
Item
Returns a single object from a collection.
Item (Index)
Index: The name or index number of the object.
Worksheets(1).Range("E5").Hyperlinks.Item(1).Follow