Jump to content
Sign in to follow this  

_WordDocAddLink Help

Recommended Posts


Hey guys

Im trying to use the _WordDocAddLink command, but wont quite work for me...

From help file:

include <Word.au3> 
$oWordApp = _WordCreate () 
$oDoc = _WordDocGetCollection ($oWordApp, 0) 
_WordDocAddLink ($oDoc, "", "www.AutoIt3.com", "", "AutoIt" & @CRLF, "Link to AutoIt") 
$oLinks = _WordDocLinkGetCollection ($oDoc) 
MsgBox(0, "Link Count", @extended)

The problem is, that the help file only give 1 example, where the 2. parameter is ""

2. parameter

Optional: The text or graphic that you want turned into a hyperlink.

"" = (Default) Uses entire document as range

This clears the entire word doc and leaves only the link <-- now quite what i was trying to :D

I accualy dont have any text or graphic i want turned into a hyperlink, i want it to make a new one.

I have tried insetting some random text (eks. asd) in the word doc, and set the 2. parameter to "asd" but that leaves me with an error.

Anyone got a solution?

Thanks in advance, BenD

Edited by BenD

Share this post

Link to post
Share on other sites

#include <Word.au3>
$oWordApp = _WordCreate()    ;_WordCreate(@ScriptDir & "\test.doc")
$oDoc = _WordDocGetCollection ($oWordApp, 0)
$oSelect = $oDoc.Application.Selection
$oFind = $oSelect.Find
For $i = 1 To 10
    $oSelect.TypeText("Adding some text, line " & String($i))
    If $i = 8 Then
        $oSelect.TypeText(@TAB & @TAB & "AutoIt" & @CRLF)
; replace first occurance of text "AutoIt" with link
With $oFind
    .Text = "AutoIt"
    .Forward = True
    .Wrap = 1
_WordDocAddLink ($oDoc, $oSelect.Range, "http://www.autoitscript.com", "", "AutoIt" & @CRLF, "Link to AutoIt")
$oLinks = _WordDocLinkGetCollection ($oDoc)
ConsoleWrite("Link Count " & @extended & @LF)

  • Like 1

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this