Table of contents
TOC
Collapse the table of content
Expand the table of content

Hyperlinks.Add Method (Publisher)

office 365 dev account|Last Updated: 8/24/2017
|
3 Contributors

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

NameRequired/OptionalData TypeDescription
TextRequiredTextRangeTextRange object. The text range to be converted into a hyperlink.
AddressOptionalStringThe address of the new hyperlink. If RelativePage is pbHlinkTargetTypeURL (default) or pbHlinkTargetTypeEmail, Address must be specified or an error occurs.
RelativePageOptionalPbHlinkTargetTypeThe type of hyperlink to add.
PageIDOptionalLongThe 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.
TextToDisplayOptionalStringThe display text of the new hyperlink. If specified, TextToDisplay replaces the text range specified by the Text argument.

Return Value

Hyperlink

Remarks

RelativePage can be one of these PbHlinkTargetType constants. The default is pbHlinkTargetTypeURL.

| pbHlinkTargetTypeEmail| | pbHlinkTargetTypeFirstPage| | pbHlinkTargetTypeLastPage| | pbHlinkTargetTypeNextPage| | pbHlinkTargetTypePageID| | pbHlinkTargetTypePreviousPage| | pbHlinkTargetTypeURL|

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 Web site, 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:="http://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
© 2018 Microsoft