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

27 posts in this topic

Messy_Code_Guy 1

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.

Share this post

Link to post

Share on other sites

water 1,615

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 pictureFor$oShapeIn$oDoc.InlineShapesConsoleWrite($oShape.Hyperlink.Address&@CRLF)Next

Share this post

Link to post

Share on other sites

Messy_Code_Guy 1

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.....,

Share this post

Link to post

Share on other sites

water 1,615

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.

Share this post

Link to post

Share on other sites

Messy_Code_Guy 1

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".

Share this post

Link to post

Share on other sites

Messy_Code_Guy 1

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.

Share this post

Link to post

Share on other sites

water 1,615

#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 pictureFor$oShapeIn$oDoc.InlineShapesConsoleWrite($oShape.Hyperlink.Address&@CRLF)Next

Similar Content

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.

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.")

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.

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

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.