Sign in to follow this  
Followers 0
urby

_worddocaddpicture

2 posts in this topic

#1 ·  Posted (edited)

I've written a lengthy script to control an application called AccPac.

It captures data after lots of navigation. Half the data can be selected with the mouse, so the script copies it to clipboard and sets it as a variable. Eventually, it uses _worddocfindreplace to replace them in what I call the "form template": a read-only word document that the script edits and saves as another, which is then printed.

I'm at the part where I hve to collect more data: these numbers cannot be selected.

So, I downloaded a screen capture utility and have it all set up so that the script makes it save four screenshots and saves them in a temp directory. The filenames/paths NEVER change.

Now, I want it to insert each picture after a string of words. That's all I need it to do right now, but I have no idea how. The whole _word... has me very confused. This is how I had it take in contents from the clipboard and put in in the doc.

#include <Word.au3>
$word = ObjGet("P:\Pro\Apps\Credit-Form.doc","word.application")
...
WinMove ( "ACCPAC Pro Series", "Customer Maintenance", "0", "0", "900", "700")
WinActivate ( "ACCPAC Pro Series", "Customer Maintenance" )
send ("!")
Send ("vra")
Send ("{enter}")
sleep ("500")
MouseClick ( "left", "575","332", "2", "0")
MouseClick ( "left", "408","371", "2", "0")
sleep("500")
Send ("{alt}ec")
sleep("500")
$balance = ClipGet ()
sleep("500")
_WordDocFindReplace ( $word, "%balance",""& $balance &"")

That's simple enough to understand: keystrokes/mouse clicks to copy, gets into word thereafter. Without all the delays the program goes nuts, btw.

Now, lets say the image is all ready to be put into word. I try

_WordDocAddPicture ( $word, "P:\Pro\Apps\Temp\total.bmp", "", "", "%total")

This should put total.bmp next to/near the text %total, but I get the followng error:

--> Word.au3 Error from function _WordDocAddPicture, $_WordStatus_InvalidDataType

HELP!!!!

I just want to get that damn function to work!

Edited by urby

Share this post


Link to post
Share on other sites



This example should give you a good starting point.

#include <Word.au3>

Const $wdCollapseEnd = 0
Const $wdCollapseStart = 1

$sSearch = "test"
$sDocPath = @ScriptDir & "\test.doc"
$sPicPath = @ScriptDir & "\test.bmp"

; Create a Microsoft Word window and open a document file
$oWordApp = _WordCreate($sDocPath)
; Get reference to the active document
$oDoc = _WordDocGetCollection($oWordApp, 0)
; Create a range of the entire document
$oRange = $oDoc.Range
; Find the specified text, updating the range with the found text
_WordDocFindReplace($oDoc, $sSearch, "", 0, $oRange)
With $oRange
    ; Insert a new line, updating the range.
    .insertAfter (@CR)
    ; Collapse the range to the end point
    .Collapse ($wdCollapseEnd)
EndWith
; Add the specified picture to the range
_WordDocAddPicture($oDoc, $sPicPath, 0, 1, $oRange)

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  
Followers 0