AddHyperlink Method [Visio 2003 SDK Documentation]
Adds a Hyperlink object to a Microsoft Office Visio shape.
objRet = object**.AddHyperlink**
objRet The Hyperlink object that is returned.
object Required. An expression that returns a Shape object.
Version added
5.0
Remarks
Using the AddHyperlink method is equivalent to adding a hyperlink to a shape by clicking Hyperlinks on the Insert menu.
If a Hyperlink object already exists for the shape, then a reference to the existing Hyperlink object is returned.
Example
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
Applies to | Shape object
See Also | Hyperlink object