Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

Shape.AddHyperlink Method (Visio)

Adds a Hyperlink object to a Microsoft Visio shape.

Version Added: Visio 5.0

expression .AddHyperlink

expression A variable that represents a Shape object.

Return Value

Hyperlink

Using the AddHyperlink method is equivalent to adding a hyperlink to a shape by clicking Hyperlink on the Insert tab.

If a Hyperlink object already exists for the shape, the method returns a reference to the existing Hyperlink object.

This example shows how to use the AddHyperlink method to add a hyperlink to a shape. It also shows how to trap errors that arise when you try to access nonexistent hyperlinks. It first attempts to access a hyperlink that does not exist, thereby throwing an error. Then it adds the hyperlink, and when it attempts to access the hyperlink a second time, no error is thrown. Before running this example, replace address with a valid Internet or intranet address.

 
Sub AddHyperlink_Example() 
 
 Dim vsoShape As Visio.Shape 
 Dim vsoHyperlink As Visio.Hyperlink 
 Dim blsCaught As Boolean 
 
 'Draw a rectangle shape on the active page. 
 Set vsoShape = ActivePage.DrawRectangle(1, 2, 2, 1) 
 
 'A shape that has no hyperlink should raise an exception 
 'when the Hyperlink property is accessed. 
 On Error GoTo lblCatch 
 
 blsCaught = False 
 Set vsoHyperlink = vsoShape.Hyperlink 
 
 If Not blsCaught Then 
 Debug.Print "ERROR - Hyperlink didn't throw an exception!" 
 End If 
 
 'Add a hyperlink to a shape. 
 Set vsoHyperlink = vsoShape.AddHyperlink 
 
 'Return an absolute address. 
 vsoHyperlink.Address = "address" 
 
 Exit Sub 
 
 lblCatch: 
 Debug.Print "Error was thrown : " & Err.Description 
 blsCaught = True 
 Resume Next 
End Sub 

Show:
© 2015 Microsoft