Jump to content

Getting links from word doc


Recommended Posts

I'm trying to run a test to get the links from a word document.

I've found several examples on how to create a new document, add a link then report on it, ... but haven't seen doing it with an existing document.

So trying this code:

#include <Word.au3>
$oWordApp = _WordCreate("D:\temp\Content.doc")
$oDocs = _WordDocGetCollection ($oWordApp, 0)

$oLinks = _WordDocLinkGetCollection ($oDocs)
MsgBox(0, "test", $oLinks & @CRLF & @extended & @CRLF & @error)     ; Returns 0, 1, 3

$sMsg = "Link Count = " & @extended & @CRLF
MsgBox(0, "test", $sMsg)                                            ; Shows: "Link Count = 0"

For $oLink In $oLinks
    $sMsg &= "TextToDisplay: " & $oLink.TextToDisplay & "  Address: " & $oLink.Address & @CRLF
Next
;>>> Get Error Here: "Variable must be of type object"
MsgBox(0, "test", "4")

MsgBox(64, "Links", $sMsg)

The document for now is just a word document I created (.doc) and added a single link. Text = "Hi" and link="www.yahoo.com"

But if you look at the code above you can see the error I'm seeing and the other msgbox'es I've put in.

Can someone point out what I'm doing wrong?

Thanks,

Terry

Link to comment
Share on other sites

I had problems with Windows 7 64 bit and Office 2010 32 bit when the AutoIt script was run for 64 bit. I changed AutoIt to run for 32 bit and everything was fine again.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I had problems with Windows 7 64 bit and Office 2010 32 bit when the AutoIt script was run for 64 bit. I changed AutoIt to run for 32 bit and everything was fine again.

That was it!!

But it is still weird that it says 0 links but then still shows me the text and address?

Terry

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...