Hyperlinks.Add method (Publisher)

Adds a new Hyperlink object to the specified Hyperlinks collection and returns the new Hyperlink object.

Syntax

expression.Add (Text, Address, RelativePage, PageID, TextToDisplay)

expression A variable that represents a Hyperlinks object.

Parameters

Name Required/Optional Data type Description
Text Required TextRange TextRange object. The text range to be converted into a hyperlink.
Address Optional String The address of the new hyperlink. If RelativePage is pbHlinkTargetTypeURL (default) or pbHlinkTargetTypeEmail, Address must be specified, or an error occurs.
RelativePage Optional PbHlinkTargetType The type of hyperlink to add. Can be one of the PbHlinkTargetType constants; the default is pbHlinkTargetTypeURL.
PageID Optional Long The page ID of the destination page for the new hyperlink. If RelativePage is pbHlinkTargetTypePageID, PageID must be specified, or an error occurs. The page ID corresponds to the PageID property of the destination page.
TextToDisplay Optional String The display text of the new hyperlink. If specified, TextToDisplay replaces the text range specified by the Text argument.

Return value

Hyperlink

Example

The following example adds hyperlinks to shape one and shape two on page one of the active publication. The first hyperlink points to an external website, and the second link points to the fourth page in the publication. Shape one and shape two must be text boxes, and there must be at least four pages in the publication for this example to work.

Dim hypNew As Hyperlink 
Dim lngPageID As Long 
Dim strPage As String 
 
With ActiveDocument.Pages(1).Shapes(1).TextFrame 
 Set hypNew = .TextRange.Hyperlinks.Add(Text:=.TextRange, _ 
 Address:="https://www.tailspintoys.com/", _ 
 TextToDisplay:="Tailspin") 
End With 
 
lngPageID = ActiveDocument.Pages(4).PageID 
strPage = "Go to page " _ 
 & Str(ActiveDocument.Pages(4).PageNumber) 
 
With ActiveDocument.Pages(1).Shapes(2).TextFrame 
 Set hypNew = .TextRange.Hyperlinks.Add(Text:=.TextRange, _ 
 RelativePage:=pbHlinkTargetTypePageID, _ 
 PageID:=lngPageID, _ 
 TextToDisplay:=strPage) 
End With

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.