Jump to content
Sign in to follow this  
zdgastineau

_WordDocAddLink Adding multiple links

Recommended Posts

zdgastineau

I have been unsuccessful in adding more than one link to a collection.  Can someone tell me what I'm doing wrong:

Local $oWordApp = _WordCreate("")
Local $oDoc = _WordDocOpen($oWordApp, $BuildDoc)
   _WordDocAddLink($oDoc, "", $BuildFolder & "IIS", "", "")
      _WordDocAddLink($oDoc, "", $BuildFolder & "sql", "", "")
    _WordDocAddLink($oDoc, "", $BuildFolder & "ssis", "", "")

 

 
$oLinks = _WordDocLinkGetCollection ($oDoc)
$sMsg = "Link Count = " & @extended & @CRLF
msgbox(0,"zdg",$sMsg)
For $oLink In $oLinks
    $sMsg &= "TextToDisplay: " & $oLink.TextToDisplay & "  Address: " & $oLink.Address & @CRLF
;msgbox(0,"zdg",$sMsg)
Next
 
Result is the a count of 1 and the first link that was added.
 
Thanks

Share this post


Link to post
Share on other sites
water

What's the value of @error after you called _WordDocAddLink?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
zdgastineau

What's the value of @error after you called _WordDocAddLink?

It was 0 each time.

   _WordDocAddLink($oDoc, "", $BuildFolder & "IIS", "", "")

   msgbox(0,"error:",@error)

      _WordDocAddLink($oDoc, "", $BuildFolder & "sql", "", "")

      msgbox(0,"error:",@error)

      _WordDocAddLink($oDoc, "", $BuildFolder & "ssis", "", "")

      msgbox(0,"error:",@error)

Share this post


Link to post
Share on other sites
water

I see the last link added ("ssis").

As a default _WordDocAddLink assigns the link to the whole document if parameter 2 is empty. Hence link 3 overwrites links 1 and 2.

You need to pass a range object as parameter 2 where you want to set the link.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
zdgastineau

I see the last link added ("ssis").

As a default _WordDocAddLink assigns the link to the whole document if parameter 2 is empty. Hence link 3 overwrites links 1 and 2.

You need to pass a range object as parameter 2 where you want to set the link.

Ah Range was the missing link.  Thank you very much for your help... here is my final resolution:

The following worked as intended.

Local $oWordApp = _WordCreate("")
Local $oDoc = _WordDocOpen($oWordApp, $BuildDoc)
Local $oDoc = _WordDocGetCollection($oWordApp, 0)
Local $oRange = $oDoc.Range
   _WordDocFindReplace($oDoc, "~WebPath~", $BuildFolder & "IIS",1, $oRange)
   _WordDocAddLink($oDoc, $oRange, $BuildFolder & "IIS", "", "")
 
   _WordDocFindReplace($oDoc, "~DBPath~", $BuildFolder & "SQL",1, $oRange)
   _WordDocAddLink($oDoc, $oRange, $BuildFolder & "SQL", "", "") 
 
   _WordDocFindReplace($oDoc, "~SSISPath~", $BuildFolder & "SSIS",1, $oRange)
   _WordDocAddLink($oDoc, $oRange, $BuildFolder & "SSIS", "", "") 
 

Share this post


Link to post
Share on other sites
water

:)

The next version of AutoIt comes with my rewrite of the Word UDF. Is much more flexible and supports the latest versions of Word.

It is already included in the latest beta version. It is NOT compatible with the current Word UDF.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
zdgastineau

:)

The next version of AutoIt comes with my rewrite of the Word UDF. Is much more flexible and supports the latest versions of Word.

It is already included in the latest beta version. It is NOT compatible with the current Word UDF.

Very good.  Thanks for all you do. These are very helpful.  FYI I'm using Word 2013 and my solution above worked. I think I'm using version v3.3.8.1 of AutoIT.

Share this post


Link to post
Share on other sites
water

Great to hear that Word 2013 seems to be "compatible" with older versions of Word.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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  

×