Messy_Code_Guy

Need a sample of how to find a picture and add a hypelink in a Word document.

27 posts in this topic

All,

I need some help with the following:
1. Finding an image in a Word doc.  I have read the help file but I cannot figure out how to reference the image in the Word doc.
2. Adding a hyperlink to that image.
3. How would I loop the add hyperlink (text) and add hyperlink (image) to replace multiple links in a document.

I have the add image and hyperlink working with the following code:

$pic = "<PHOTO>"
    $picpath = IniRead(@ScriptDir & "\Config\Config.ini", "User Info", "Picture", 0)
    Local $oRange = _Word_DocFind($oDoc, $pic)
    _Word_DocPictureAdd($oDoc, $picpath, Default, Default, $oRange)
    _Word_DocFindReplace($oDoc, $pic, "", Default, 0, True, True)
    If @error Then
        $file1 = FileOpen("C:\Tech\Log_Files\_Error_Logs\Error_LOG.txt", 9)
        _FileWriteLog($file1, "," & @ComputerName & "," & @UserName & ",Error adding a picture to the document. " & $picpath & " " & " @error = " & @error & " @extended = " & @extended)
        FileClose($file1)
    EndIf



    $Link = "<LINKEDIN>"
    $LinkedIn = IniRead(@ScriptDir & "\Config\Config.ini", "User Info", "LinkedIn", 0)
    Local $oRange = _Word_DocFind($oDoc, $Link)
    _Word_DocLinkAdd($oDoc, $oRange, $LinkedIn, Default, "Click here to visit my LinkedIn page. " & @CRLF & $LinkedIn, "LinkedIn")
    If @error Then
        $file1 = FileOpen("C:\Tech\Log_Files\_Error_Logs\Error_LOG.txt", 9)
        _FileWriteLog($file1, "," & @ComputerName & "," & @UserName & ",Error adding a link to the document. " & $LinkedIn & " " & " @error = " & @error & " @extended = " & @extended)
        FileClose($file1)
    EndIf

I just can't figure out how to find the images in a Word doc.

Thanks for reading my post!


 

"The only thing necessary for the triumph of evil is for good men to do nothing".

Edmund Burke
 

Share this post


Link to post
Share on other sites



The UDF does not support working with images the way you need it.

Get the Shapes collection and search for the item you need to add a link to it.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

Water-

Thanks for the reply.  I am not sure how to get the shapes collection.  Do you have a small example of the code needed?

Thanks,


 

"The only thing necessary for the triumph of evil is for good men to do nothing".

Edmund Burke
 

Share this post


Link to post
Share on other sites

Will post an example as soon as I return to my Office.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

Thanks for the assist!  Post the code when you have time. :)


 

"The only thing necessary for the triumph of evil is for good men to do nothing".

Edmund Burke
 

Share this post


Link to post
Share on other sites

Something like this. There is no error handling so it might crash if you do not use InlineShapes.

#include <Word.au3>
$oWord = _Word_Create()
$oDoc = _Word_DocOpen($oWord, "C:\temp\test.docx")
; Set Picture 1 to Microsoft, Picture 2 to Google
$oDoc.Hyperlinks.Add($oDoc.InlineShapes(1), "http://www.microsoft.com")
$oDoc.Hyperlinks.Add($oDoc.InlineShapes(2), "http://www.google.com")
; Loop through the InlineShape collection and display the Hyperlinkfor each picture
For $oShape In $oDoc.InlineShapes
    ConsoleWrite($oShape.Hyperlink.Address & @CRLF)
Next

 

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

Thanks water!  I will give it a try.  :)


 

"The only thing necessary for the triumph of evil is for good men to do nothing".

Edmund Burke
 

Share this post


Link to post
Share on other sites

If it doesn't work please post a small sample document (with all sensitive information removed) so i have something to play with.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

Water-

Here is a sample document that is saved as a Word .mht.  I use this doc to create sigs for Outlook in Office 365 (2013).
If you can just add a link to Google to each of the images it would be much appreciated.

Thanks for the assist and if you have an address I can send the check to.....,  :)

Default RMLO_SIG.mht


 

"The only thing necessary for the triumph of evil is for good men to do nothing".

Edmund Burke
 

Share this post


Link to post
Share on other sites

I'm a bit confused now.
Do you want to insert the link into a doc or a mht file type?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

#11 ·  Posted (edited)

Sorry,

I want to add the link to the image in a .mht if possible.  After I add all the info I need I do a save as function to turn it into an Outlook signature.

_Word_DocSaveAs($oDoc, $sDocument, $wdFormatHTML)
_Word_DocSaveAs($oDoc, $sDocument, $wdFormatRTF)
_Word_DocSaveAs($oDoc, $sDocument, $wdFormatTEXT)

Thanks for the help!

Edited by Messy_Code_Guy

 

"The only thing necessary for the triumph of evil is for good men to do nothing".

Edmund Burke
 

Share this post


Link to post
Share on other sites

You know that my OutlookEX UDF contains a function to create signatures? Please check _OL_MailSignatureCreate.au3 example script to get an idea how Word and Outlook can be combined to create a signature. Then use _OL_MailSignatureSet to set the signature.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

Water-
Very cool UDF by the way.  I have been using Word to create the template and add the info to the template using the Word UDF.  The only function I am missing is the find a picture and add a hyperlink to that picture.  I do have a working sample of the Outlook UDF Test that creates a signature and it works well.  Quick question! What language do you use to program all of UDF's in Autoit?

Thanks,


 

"The only thing necessary for the triumph of evil is for good men to do nothing".

Edmund Burke
 

Share this post


Link to post
Share on other sites

The UDFs are written in AutoIt as well.

Can you please post the code to create the template? It should be easy to add the links.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

Water-
Here is the code I have to fill out the Word .mht file.  I do not have the search and add link function for the 11 images in the document. I am also adding the modified word document that has updated text place holders for the ini file. I have also added the .au3 for the template creation code. The code is a little sloppy but it works for me.

Thanks again for your help.

Default RMLO_SIG.mht

Word_Test2.au3


 

"The only thing necessary for the triumph of evil is for good men to do nothing".

Edmund Burke
 

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Maybe I need another cup of coffee but why do you need to work with a mht file type?
According to Wikipedia this is a web archive format: https://en.wikipedia.org/wiki/MHTML

I will try to provide an example based on a true Word docx document.

 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

I use .mht files so I can embed the images and keep everything in one nice and tidy file.  I know it is not the best choice but it works. Thanks for the assistance and a .docx will work fine.:)


 

"The only thing necessary for the triumph of evil is for good men to do nothing".

Edmund Burke
 

Share this post


Link to post
Share on other sites

Save your .mht file as .docx and give this example script a try:

#include <Word.au3>
$oWord = _Word_Create()
$oDoc = _Word_DocOpen($oWord, "C:\temp\Default RMLO_SIG.docx")
$FBName = "http://www.facebook.com"
; Set Picture 1 to Facebook
_Word_DocLinkAdd($oDoc, $oDoc.InlineShapes(1).Range, $FBName, Default, "Click here to visit my facebook page. " & @CRLF & $FBName, "FB")
; Loop through the InlineShape collection and display the Hyperlink for each picture
For $oShape In $oDoc.InlineShapes
    ConsoleWrite($oShape.Hyperlink.Address & @CRLF)
Next

 

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

Water-

You ROCK!  Thanks for the help and the kick A$$ UDF's you have written.  I only have one question.  How do you figure out which image is what number when using inlineShapes?

Thanks again!


 

"The only thing necessary for the triumph of evil is for good men to do nothing".

Edmund Burke
 

Share this post


Link to post
Share on other sites

Will need to check tomorrow. Maybe we can set an unique identifier when creating the Word document.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

  • Similar Content

    • SimTheNo1
      By SimTheNo1
      I am busy with building a solution for change monitoring of VOIP call program and to be properly automated means among others need for some limited OCR functionality. Current works of others are way too much overkill for this case what makes the need to build it myself. But to do it properly I significantly have to increase my knowledge about digital graphics management.
      For now I already have discovered here and there some mind blowing  Autoit miracles what can be achieved with Windows own possibilities to manipulate that what is output to the monitor. And as far I can judge there are 2 options to process graphics without use of any external libraries like ImageMagick, FreeImage and so on. These are:
       WinAPI  GDIPlus It is for me quite obvious to have various holes in general understanding of graphics and it is once more very clear what advantages gives consistent general study in 1 or another official institutions like University.  Cause there you are introduced into certain domain of knowledge in a way which usually has been perfected over long period of time. So you are not overloaded by stuff which requires a certain amount of information to be initially clear for you. For example, before starting to solve physics you first learn to read, count and so on and then move to subjects like physics.
      Though in my case opportunity to study in such educational system I had only for 8 years, from my 7th to 15th year of age in the country that was falling apart now Ukraine but used to be USSR, was all what it was. After have immigrated to Netherlands possibilities to study further haven't occur. And this therefor causes often various implications when going deep in that or another field of practical knowledge acquiring for any needed physical result, like programming to perform enormous amount of tasks. In this particular case automating VOIP call program.
      Anyway, right now I think the best direction to move is to concentrate on as basic as possible image management and if someone would maybe explain in general what is a pixel will definitely help. Particularly I am very curious about how to do picture manipulations in Autoit. Especially would help a lot to produce eventually following functions:
      createImage($imageFileName, $width, $height, $color) readImagePixel($imageFileName, $x, $y)  writeImagePixel($imageFileName, $x, $y) I do not know exactly how image is handled in computer but preferably above mentioned functions should deal with so far possible origin of graphics creation on computer. But nevertheless I definitely would love to hear any proposition for solution.
      The problem with explaining screenshots:
       VOIPConnect full Window  Part of Window with control to monitor for changes  Exact location of area where actual changes occur and have to be processed  It comes down to a rectangle of approximately 51 pixel wide and 7 pixel high. In fact if I get to learn as far as to be able exactly read, write and compare 2 images consistently across different computers I could narrow down then even further the area to watch as little as a square of 2-5 pixels wide. 
      To finish here is last detail about particularly no need for ultra fast solution at all. This because it is needed only once when it is first run on a new computer and to have to wait few minutes while it is being set instead of just a few seconds make no sence.
      This is it and what I too think to do beside this very particular case is to purify out beautiful generic Autoit functions for core image manipulation by using WinAPI or/and GDIPlus. 
    • Jury
      By Jury
      I've failed to find an example of _Word_DocFindReplace which searches for formatted text (I'm looking for stand alone paragraph marks that are formatted other than normal i.e. Bold Italic, Underlined). 
      The reason being that when converting a Word document to html one of the main problems in the results is that a stand alone paragraph mark is converted to an html space that retains the formatting ...>&nbsp;<... thus showing up as a underline _  in a browser when it should be blank.  I've played around with the script and got it to at least un-bold  the first paragraph mark regardless if it was bold or not but I'd like to clear all formatting from any stand alone paragraph marks in the whole document.  Below is what I've done so far (not much more than in the help file I'm afraid) .  Way down at the bottom of the _Word_DocFindReplace  help  text is this parameter but without any examples to be found :
      $bFormat   [optional] True to have the find operation locate formatting in addition to or instead of the find text (default = False) #include <MsgBoxConstants.au3> #include <Word.au3> $processing = @MyDocumentsDir & '\AutoIt_code\getter\processing\' Global $oWord = _Word_Create() Global $sTestfile = $processing & "Testing.docx" ConsoleWrite($sTestfile & @CRLF) Global $oDoc = _Word_DocOpen($oWord, $sTestfile) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error opening file = '" & $sTestfile & "'" & @CRLF & "@error = " & @error & ", @extended = " & @extended) $oRangeFound = _Word_DocFind($oDoc, "^p", Default, Default) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error locating paragraph control character in the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $oRangeFound.Bold = False If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error inserting text after the paragraph control character in the document." & @CRLF & "@error = " & @error & _ ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", "Paragraph control character successfully replaced." & @CRLF & _ "Text inserted in paragraph 2.")  
    • Ian_Mac
      By Ian_Mac
      Func dg_get_images() $x1=0 $y1=0 ;MsgBox(0,"start","start") do $result = _ImageSearch("C:\Users\Server\Desktop\my project\image.png",1,$x1,$y1,0) until $result = 1; if $result=1 Then MouseMove($x1,$y1,3) MouseClick("left", $x1,$y1, 1) WinWait("[Title:TightVNC File Transfer]", "", 10) EndIf  this code works when i search the image, but when i change the location of the desktop icon it can't find the desktop icon anymore.   i wanna try image search area. but i don't know how to use it because i cant understand the parameter for the image search area.  please help me how to solve it thank you in advance.
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone
      I am working on a little script, which takes some data from a SQLite DB and should create a sort of report, inserting rows in a Word Document... I arrived at the point of:
      _Word_DocTableWrite() and, I don't know how to set the range parameter? What does that specify? 
      Thanks a lot for the help
      EDIT:
      Managed to write a table in the Word document, but now I get an error when I save the document with _Word_DocSaveAs(), with error 2.
      Which are possible causes? Thanks a lot, again
      EDIT 2:
      ... And, how can I set a border to the table? Maybe, with a sort of auto-formatting for text ( larger is the text, larger is the height/width of the table's cell ).
      Thanks  
      EDIT 3 ( bug ):
      Including the parameter $WdSaveChanges in the function _Word_DocSaveAs(), a save dialog box appears, and it should not do it, as it's written in the MSDN documentation:
      wdSaveChanges -1 Save pending changes automatically without prompting the user. Thanks again for everyone will answer to me  
    • anthonyjr2
      By anthonyjr2
      I'm using the Word UDF for the first time, and I'm having some trouble with _Word_DocFind(). There isn't really much talk around the forums about this so it's hard to find any support on the issue I'm having. Here's my code:
      #include <Word.au3> $listPath = @ScriptDir & "\AMCH OFFSET 042617.docx" $pWord = _Word_Create() $oWord = _Word_DocOpen($pWord, $listPath) Local $ctr = 0 Local $searchRange = _Word_DocFind($oWord, "Claim Number") If Not @error Then $ctr += 1 EndIf While ($searchRange <> 0) $searchRange = _Word_DocFind($oWord, "Claim Number", 0, $searchRange) If Not @error Then $ctr += 1 EndIf $searchRange.Select WEnd My problem is that it doesn't seem to find a match of the string on any page after the second. When I run the script, it just loops indefinitely on the second page. I can't post an example of the word document because it is medical data, but every page is basically the same and every page has the string I am looking for on it. Also I tried checking @error after doing a find and it is never set, so I don't think that's the problem.