AddHyperlinkToDocument Method

Adds a hyperlink pointing to a ConceptDraw to the hyperlink collection of the document. Returns the ID (the ID property) of the added hyperlink.

Applies to: Document object

Syntax

[[Let] linkIDRet = ] object.AddHyperlinkToDocument ( fileName, [localPath], [pageID], [shapeID] )

The AddHyperlinkToDocument method syntax has these parts:

Part Description
object Required. An expression that returns an instance of the Document object.
fileName Required. An expression that returns a String value. Specifies the filename (with the full or relative path) to which the added hyperlink will point.
localPath Optional. An expression that returns a Boolean value. If localPath is True, then the fileName represents a relative path (with respect to the folder, in which the document is located). Otherwise fileName contains the full path to the file. The default value is False.
pageID Optional. An expression that returns a Long value. Represents the ID of the document page to which the added hyperlink will point. The default value is 0, which means the hyperlink doesn't point to any specific page.
shapeID

Optional. An expression that returns a Long value. Represents the ID of the shape to which the added hyperlink will point. The default value is 0, which means the hyperlink doesn't point to any specific shape.

linkIDRet Optional. A Long type variable.

Remarks

If the hyperlink was added successfully, the AddHyperlinkToDocument method returns the ID of the added hyperlink. If the hyperlink collection of the document already contains a hyperlink with the same properties, the method doesn't create a new hyperlink, but returns the ID of the identical hyperlink. In all other cases the method returns 0.

Note, that the method can't add a hyperlink with no filename. That is, fileName must contain at least one character.

A hyperlink created with the AddHyperlinkToDocument method has the cdLinkToFile type (see the LinkType property).

Example

This example contains a document-level script. The program creates a rectangle that contains a hyperlink pointing to a ConceptDraw document, chosen by the user. The hyperlink is added by using the AddHyperlinkToDocument method. In order to see the result of this example, the user needs to point the hyperlink to a ConceptDraw document file, and specify the page and shape IDs to which the hyperlink will point.

' Declare variables
Dim shp As Shape
Dim linkID As Long
Dim pageID As Long
Dim shapeID As Long
Dim fileName As String

' Get the attributes needed to create hyperlink:
    ' Get file name
    fileName = GetOpenFileName( "cdd", ,"Choose file!" )

if fileName <> "" AND fileName <> Null Then

    ' Get page ID
    pageID = InputBox( "Enter page ID:" )
    ' Get shape ID
    shapeID= InputBox( "Enter shape ID:" )

    ' Add hyperlink using the provided filename
    Let linkID = thisDoc.AddHyperlinkToDocument( fileName, True, pageID, shapeID )

    ' Draw rectangle
    Set shp = thisDoc.ActivePage.DrawRect( 100,100,700,500 )

    ' Assign text to rectangle
    shp.Text = fileName

    ' Assign hyperlink to rectangle
    shp.Hyperlink = linkID

    ' Set double-click action to open hyperlink
    shp.DblClick = 4
Else
    MsgBox( "You did not choose any file!" )
End If

 

See Also

ID property, LinkType property, AddHyperlinkToFile method, AddHyperlinkToPageShape method, AddHyperlinkToURL method, Hyperlink method, HyperlinkByID method, HyperlinksNum method, RemoveUnusedHyperlinks method, Hyperlink object