Hyperlink.SetPageRelative method (Publisher)

Sets the target type for the specified hyperlink.

Syntax

expression.SetPageRelative (RelativePage)

expression A variable that represents a Hyperlink object.

Parameters

Name Required/Optional Data type Description
RelativePage Required PbHlinkTargetType The target type of the hyperlink. Can be one of the PbHlinkTargetType constants declared in the Microsoft Publisher type library.

Example

The following example adds four new hyperlinks to shape one on page one of the active publication and sets their targets accordingly.

Sub SetHyperlinkRelativeTarget() 
 Dim hypNew As Hyperlink 
 Dim txtRng As TextRange 
 
 ActiveDocument.Pages(1).Shapes _ 
 .AddTextbox Orientation:=pbTextOrientationHorizontal, _ 
 Left:=10, Top:=10, Width:=200, Height:=200 
 
 Set txtRng = ActiveDocument.Pages(1).Shapes(1) _ 
 .TextFrame.TextRange 
 
 txtRng.Text = "First Page" & vbCrLf 
 
 Set txtRng = ActiveDocument.Pages(1).Shapes(1) _ 
 .TextFrame.TextRange 
 Set hypNew = ActiveDocument.Pages(1).Shapes(1).TextFrame _ 
 .TextRange.Hyperlinks.Add(Text:=txtRng, _ 
 Address:="https://www.tailspintoys.com/") 
 
 'Change hyperlink to be a Page-relative link 
 hypNew.SetPageRelative RelativePage:=pbHlinkTargetTypeFirstPage 
 
 txtRng.Collapse pbCollapseEnd 
 txtRng.Text = "Previous Page" & vbCrLf 
 
 Set hypNew = ActiveDocument.Pages(1).Shapes(1).TextFrame _ 
 .TextRange.Hyperlinks.Add(Text:=txtRng, _ 
 Address:="https://www.tailspintoys.com/") 
 
 hypNew.SetPageRelative RelativePage:=pbHlinkTargetTypePreviousPage 
 
 txtRng.Collapse pbCollapseEnd 
 txtRng.Text = "Next Page" & vbCrLf 
 Set hypNew = ActiveDocument.Pages(1).Shapes(1) _ 
 .TextFrame.TextRange.Hyperlinks.Add(Text:=txtRng, _ 
 Address:="https://www.tailspintoys.com/") 
 hypNew.SetPageRelative RelativePage:=pbHlinkTargetTypeNextPage 
 
 txtRng.Collapse pbCollapseEnd 
 txtRng.Text = "Last Page" & vbCrLf 
 Set hypNew = ActiveDocument.Pages(1).Shapes(1) _ 
 .TextFrame.TextRange.Hyperlinks.Add(Text:=txtRng, _ 
 Address:="https://www.tailspintoys.com/") 
 hypNew.SetPageRelative RelativePage:=pbHlinkTargetTypeLastPage 
 
End Sub

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.