# Function Reference

# _Word_DocLinkAdd

Adds a hyperlink to the document

#include <Word.au3>
_Word_DocLinkAdd ( $oDoc [, $oAnchor = Default [, $sAddress = Default [, $sSubAddress = Default [, $sScreenTip = Default [, $sTextToDisplay = Default [, $sTarget = Default]]]]]] )

## Parameters

$oDoc | Word document object
$oAnchor | [optional] Range object for the text or graphic to be turned into a hyperlink (default = Use entire document as range)
$sAddress | [optional] The address for the specified link. The address can be an E-mail address, an Internet address or a file name (default = link to the specified document is used)
$sSubAddress | [optional] The name of a location within the destination file, such as a bookmark, named range or slide number (default = None)
$sScreenTip | [optional] The text that appears as a ScreenTip when the mouse pointer is positioned over the specified hyperlink (default = Uses value of $sAddress)
$sTextToDisplay | [optional] The display text of the specified hyperlink. The value of this argument replaces the text or graphic specified by $oAnchor (default = Uses value of $sAddress)
$sTarget | [optional] The name of the frame or window in which you want to load the specified hyperlink

## Return Value

Success: | 1.
Failure: | 0 and sets the @error flag to non-zero.
@error: | 1 - $oDoc is not an object 2 - Error occurred when adding the link. @extended is set to the COM error code 3 - $oAnchor is not 0 but is not a range object

## Related

_Word_DocLinkGet

## Example

### Example 1

    #include "Extras\HelpFileInternals.au3"

    #include <MsgBoxConstants.au3>
    #include <Word.au3>

    ; Create application object
    Local $oWord = _Word_Create()
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocLinkAdd Example", _
            "Error creating the Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    ; Open test.doc read-only
    Local $oDoc = _Word_DocOpen($oWord, _Extras_PathFull("Test.doc"), Default, Default, True)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocLinkAdd Example", _
            "Error opening '.\Extras\Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

    ; Make the fourth word of the document a link to the AutoIt homepage
    Local $oRange = _Word_DocRangeSet($oDoc, -1, $wdWord, 3, $wdWord, 1)
    _Word_DocLinkAdd($oDoc, $oRange, "http://www.autoitscript.com")
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocLinkAdd Example", _
            "Error adding a link to the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocLinkAdd Example", "Word 4 of the document is now a link to the AutoIt homepage.")

### Example 2

    #include "Extras\HelpFileInternals.au3"

    #include <MsgBoxConstants.au3>
    #include <Word.au3>

    ; Create application object
    Local $oWord = _Word_Create()
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocLinkAdd Example", _
            "Error creating the Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    ; Open test.doc read-only
    Local $oDoc = _Word_DocOpen($oWord, _Extras_PathFull("Test.doc"), Default, Default, True)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocLinkAdd Example", _
            "Error opening '.\Extras\Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

    ; Add a link to the end of the document and set parameters
    ; ScreenTip and TextToDisplay
    Local $oRange = _Word_DocRangeSet($oDoc, -2) ; Go to end of document
    $oRange.Text = " " ; Add a space at the end of the document
    $oRange = _Word_DocRangeSet($oDoc, -2)
    _Word_DocLinkAdd($oDoc, $oRange, "http://www.autoitscript.com", Default, "AutoIt homepage", _
            "Hyperlink 3 - Another link to the AutoIt homepage")
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocLinkAdd Example", _
            "Error adding a link to the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocLinkAdd Example", "Hyperlink added to the end of the document.")