Sign in to follow this  
Followers 0
Kohr

More help with _WordDocAddPicture

4 posts in this topic

I am basically trying to use the functions from Word.au3 to replace methods I used before. What I am doing is I would enter text in Word, insert a picture, then insert a PageBreak. This would give me a nice text/picture view for each page in Word. This is represented using the following code.

#include <Word.au3>
$DefaultPath = "C:\Program Files\temp\"
$oWordApp = _WordCreate (@DesktopDir & "\WordOutput2.doc", 0, 0)
$oDoc = _WordDocGetCollection ($oWordApp, 0)
    With $oWordApp.Selection
        .TypeText ("Text on Line 1" & @CRLF)
        .TypeText (@CRLF)
        .InlineShapes.AddPicture ($DefaultPath & "Temp\MWSnap.png", False, True)
        .TypeText (Chr("12"))
    EndWith
_WordDocSaveAs ($oDoc)
_WordQuit ($oWordApp)

What I wanted to do is use function _WordDocAddPicture to replace the code ".InlineShapes.AddPicture ($DefaultPath & "Temp\MWSnap.png", False, True)" but I am not exactly sure how to do this. I did notice there is a "range" option to that function but I am having terrible luck using it.

When I did get it to work it would insert the picture before any of the text even though I had ".TypeText" before the function (which is probably correct I am just not grasping why).

I did look at http://msdn.microsoft.com/library/default....gWithRanges.asp but I guess my knowledge is weak using range vs. selection.

Any suggestions would be great. Thanks.

Kohr

Share this post


Link to post
Share on other sites



I believe this accomplishes what you are needing.

#include <Word.au3>
$sPath = @ScriptDir & "\"
$oWordApp = _WordCreate ($sPath & "WordOutput2.doc", 0, 0)
$oDoc = _WordDocGetCollection ($oWordApp, 0)
$oRng = $oDoc.Range
With $oRng
    .Text = "Text on Line 1" & @CRLF & @CRLF
    .Collapse (0) ;0 = end, 1 = start
EndWith
$oPic = _WordDocAddPicture ($oDoc, $sPath & "MWSnap.png", False, True, $oRng)
With $oPic.Range
    .Collapse (0) ;0 = end, 1 = start
    .InsertBreak (7) ;6 = line, 7 = page
    .Text = "Text on the second page."
EndWith
_WordDocSaveAs ($oDoc)
_WordQuit ($oWordApp)

Share this post


Link to post
Share on other sites

No problem, glad I was able to help.

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