Class Hyperlink (Excel VBA)

The class Hyperlink represents a hyperlink.

The main procedures of class Hyperlink are Delete, Hyperlinks.Add and Hyperlinks.Delete

Set

To use a Hyperlink class variable it first needs to be instantiated, for example

Dim hyp as Hyperlink
Set hyp = ActiveCell.Hyperlinks(Index:=1)

The following procedures can be used to set variables of type Hyperlink: Hyperlinks.Item, Hyperlinks.Add, Shape.Hyperlink, Chart.Hyperlinks, Range.Hyperlinks and Worksheet.Hyperlinks

For Each

Here is an example of processing the Hyperlink items in a collection.

Dim hyp As Hyperlink
For Each hyp In ActiveCell.Hyperlinks
	
Next hyp

Methods

These are the main methods of the Hyperlink class

Delete - Deletes the object.

ActiveCell.Hyperlinks(1).Delete

Hyperlinks.Add - Adds a hyperlink to the specified range or shape.

With Worksheets(1) 
 .Hyperlinks.Add Anchor:=.Range("a5"), _ 
 Address:="https://example.microsoft.com", _ 
 ScreenTip:="Microsoft Web Site", _ 
 TextToDisplay:="Microsoft" 
End With

Hyperlinks.Delete - Deletes the object.

ActiveCell.Hyperlinks.Delete

Other Methods

AddToFavorites - Adds a shortcut to the workbook or hyperlink to the Favorites folder.

CreateNewDocument - Creates a new document linked to the specified hyperlink.

Follow - Displays a cached document, if it's already been downloaded. Otherwise, this method resolves the hyperlink, downloads the target document, and displays the document in the appropriate application.

Properties

Address returns or sets a String value that represents the address of the target document.

EmailSubject returns or sets the text string of the specified hyperlink's email subject line. The subject line is appended to the hyperlink's address.

Name returns a String value that represents the name of the object.

Parent returns the parent object for the specified object. Read-only.

Range returns a Range object that represents the range that the specified hyperlink is attached to.

ScreenTip returns or sets the ScreenTip text for the specified hyperlink.

Shape returns a Shape object that represents the shape attached to the specified hyperlink.

SubAddress returns or sets the location within the document associated with the hyperlink.

TextToDisplay returns or sets the text to be displayed for the specified hyperlink. The default value is the address of the hyperlink.

Type returns a Long value, containing an MsoHyperlinkType constant, that represents the location of the HTML frame.

Hyperlinks.Count returns a Long value that represents the number of objects in the collection.

Hyperlinks.Item returns a single object from a collection.

Hyperlinks.Parent returns the parent object for the specified object. Read-only.