Class Hyperlink (Word VBA)

The class Hyperlink represents a hyperlink. The Hyperlink object is a member of the Hyperlinks collection.

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

Set

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

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

The following procedures can be used to set variables of type Hyperlink: Hyperlinks.Add, Hyperlinks.Item, InlineShape.Hyperlink, Shape.Hyperlink, ShapeRange.Hyperlink, Document.Hyperlinks, Range.Hyperlinks and Selection.Hyperlinks

For Each

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

Dim hyp As Hyperlink
For Each hyp In Selection.Hyperlinks
	hyp.AddToFavorites
Next hyp

Methods

These are the main methods of the Hyperlink class

Delete - Deletes the specified hyperlink.

Selection.Hyperlinks(1).Delete

Hyperlinks.Add - Returns a Hyperlink object that represents a new hyperlink added to a range, selection, or document.

Dim hyp As Hyperlink
Set hyp = Selection.Hyperlinks.Add(Anchor:=)

Other Methods

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

Dim strFileName As String: strFileName =  
Selection.Hyperlinks(1).CreateNewDocument FileName:=strFileName, EditNow:=True, Overwrite:=True

Follow - Displays a cached document associated with the specified Hyperlink object, if it has already been downloaded. Otherwise, this method resolves the hyperlink, downloads the target document, and displays the document in the appropriate application.

Selection.Hyperlinks(1).Follow

Properties

Address returns or sets the address (for example, a file name or URL) of the specified hyperlink.

Selection.Hyperlinks(1).Address =

EmailSubject returns or sets the text string for the specified hyperlink's subject line.

Selection.Hyperlinks(1).EmailSubject =

ExtraInfoRequired true if extra information is required to resolve the specified hyperlink.

Dim booExtraInfoRequired As Boolean
booExtraInfoRequired = Selection.Hyperlinks(1).ExtraInfoRequired

Name returns the name of the specified object.

Dim strName As String
strName = Selection.Hyperlinks(1).Name

Parent returns an object that represents the parent object of the specified Hyperlink object.

Dim objParent As Object
Set objParent = Selection.Hyperlinks(1).Parent

Range returns a Range object that represents the portion of a document that is contained within a hyperlink.

Dim rngRange As Range
Set rngRange = Selection.Hyperlinks(1).Range

ScreenTip returns or sets the text that appears as a ScreenTip when the mouse pointer is positioned over the specified hyperlink.

Selection.Hyperlinks(1).ScreenTip =

Shape returns a Shape object for the specified hyperlink or diagram node.

Dim shpShape As Shape
Set shpShape = Selection.Hyperlinks(1).Shape

SubAddress returns or sets a named location in the destination of the specified hyperlink.

Selection.Hyperlinks(1).SubAddress =

Target returns or sets the name of the frame or window in which to load the hyperlink.

Selection.Hyperlinks(1).Target =

TextToDisplay returns or sets the specified hyperlink's visible text in a document.

Selection.Hyperlinks(1).TextToDisplay =

Type returns the hyperlink type.

Dim mhtType As Office.MsoHyperlinkType
mhtType = Selection.Hyperlinks(1).Type

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

Dim lngCount As Long
lngCount = Selection.Hyperlinks.Count

Hyperlinks.Parent returns an object that represents the parent object of the specified Hyperlinks object.

Dim objParent As Object
Set objParent = Selection.Hyperlinks.Parent