Class Hyperlinks (Word VBA)

The class Hyperlinks represents the collection of Hyperlink objects in a document, range, or selection. To use a Hyperlinks class variable it first needs to be instantiated, for example


Dim hyps as Hyperlinks
Set hyps = Selection.Hyperlinks

For Each

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


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

Add

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

Add (Anchor, Address, SubAddress, ScreenTip, TextToDisplay, Target)


ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _ 
 Address:="http:\\www.microsoft.com"

Arguments

The following argument is required

Anchor (Hyperlink) - The text or graphic that you want turned into a hyperlink.

Optional arguments

The following arguments are optional

Address (String) - The address for the specified link. The address can be an email address, an Internet address, or a file name. Note that Microsoft Word doesn't check the accuracy of the address.

SubAddress (String) - The name of a location within the destination file, such as a bookmark, named range, or slide number.

ScreenTip (String) - The text that appears as a ScreenTip when the mouse pointer is positioned over the specified hyperlink. The default value is "Address".

TextToDisplay (String) - The display text of the specified hyperlink. The value of this argument replaces the text or graphic specified by Anchor.

Target (String) - The name of the frame or window in which you want to load the specified hyperlink.

Count

Returns a Long that represents the number of hyperlinks in the collection.


Dim lngCount As Long
lngCount = Selection.Hyperlinks.Count

Item

Returns an individual Hyperlink object in a collection.

Item (Index)

Index: The individual object to be returned. Can be a Long indicating the ordinal position or a String representing the name of the individual object.


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