Dieuz Posted December 21, 2007 Posted December 21, 2007 Hi, What would be the best way to replace text in a word document with an image. In word there's already a function to replace text by text but I would like to replace texte by an image. Is there any autoit script related to that? Thanks,
xzaz Posted December 21, 2007 Posted December 21, 2007 http://www.google.nl/search?hl=nl&clie...oeken&meta= Small Color Picker v0.2 | Travian bot
Moderators big_daddy Posted December 22, 2007 Moderators Posted December 22, 2007 I wanted to make somewhat of an advanced example, so sorry if it is confusing. expandcollapse popup#include <Word.au3> $iFound = 0 $oWordApp = _WordCreate(@ScriptDir & "\Test.doc") $oDoc = _WordDocGetCollection($oWordApp, 0) ; Specifies a range object of the entire document $oRng = $oDoc.Range ; Loop through found items While Not @error ; Search for "<Picture?>" in the range specified above ; After searching the range is changed to the found text _WordDocFindReplace($oDoc, "\<Picture?\>", "", 0, $oRng, 0, 0, 1, 0, 0, 1, 0) If Not @error Then ; Duplicates range leaving the original unchanged $oTempRng = $oRng.Duplicate ; Save the text of the found range ; Set the text to null With $oTempRng $sText = .Text .Text = "" EndWith ; Find the text between < & > $aMatch = StringRegExp($sText, "\<(.*)\>", 1) If Not @error Then ; Replace the range with the correct image _WordDocAddPicture($oDoc, @ScriptDir & "\" & $aMatch[0] & ".jpg", 0, 1, $oTempRng) EndIf $iFound += 1 EndIf WEnd If $iFound > 0 Then MsgBox(0, "Success", "Found " & $iFound & " occurrences.") Else MsgBox(0, "Error", "Not Found") EndIf All files needed for a working example _WordDocReplaceWithImage.zip
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now