AddHyperlinkToFile Method

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

Applies to: Document object

Syntax

[[Let] linkIDRet = ] object.AddHyperlinkToFile ( filename, [localPath] )

The AddHyperlinkToFile 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.

linkIDRet Optional. A Long type variable.

Remarks

If the hyperlink was added successfully, the AddHyperlinkToFile 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.

A hyperlink created with the AddHyperlinkToFile 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 file, chosen by the user. The hyperlink is added by using the AddHyperlinkToFile method.

' Declare variables
Dim shp As Shape Dim linkID As Long Dim fileName As String ' Get the name of the file fileName = GetOpenFileName( ,,"Choose file!" ) if fileName <> "" AND fileName <> Null Then ' Add hyperlink using the provided filename Let linkID = thisDoc.AddHyperlinkToFile( fileName ) ' 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, AddHyperlinkToDocument method, AddHyperlinkToPageShape method, AddHyperlinkToURL method, Hyperlink method, HyperlinkByID method, HyperlinksNum method, RemoveUnusedHyperlinks method, Hyperlink object