Share via


Hyperlink Object (Publisher)

Represents a hyperlink. The Hyperlink object is a member of the Hyperlinks collection and the Shape and ShapeRange objects.

Example

Use the Hyperlink property to return a Hyperlink object associated with a shape (a shape can have only one hyperlink). The following example deletes the hyperlink associated with the first shape in the active document.

Sub DeleteHyperlink() 
 ActiveDocument.Pages(1).Shapes(1).Hyperlink.Delete 
End Sub

Use Hyperlinks(index), where index is the index number, to return a single Hyperlink object from a document, range, or selection. The following example deletes the first hyperlink in the selection.

Sub DeleteSelectedHyperlink() 
 If Selection.TextRange.Hyperlinks.Count >= 1 Then 
 Selection.TextRange.Hyperlinks(1).Delete 
 End If 
End Sub

Use the Add method to add a hyperlink. The following example adds a hyperlink to the selected text.

Sub AddHyperlinkToSelectedText() 
 Selection.TextRange.Hyperlinks.Add Text:=Selection.TextRange, _ 
 Address:="http://www.tailspintoys.com/" 
End Sub

Use the Address property to add or change the address to a hyperlink. The following example adds a shape to the active publication and then adds a hyperlink to the shape.

Sub AddHyperlinkToShape() 
 With ActiveDocument.Pages(1).Shapes.AddShape _ 
 (Type:=msoShape5pointStar, Left:=200, _ 
 Top:=200, Width:=300, Height:=300) 
 .Hyperlink.Address = "http://www.tailspintoys.com/" 
 End With 
End Sub