Sign in to follow this  
Followers 0
Odilo60

Insert image to Word

12 posts in this topic

Hi everyboby,

I'm using AutoIt for a while and it does work out fine.

Now I'm searching for a solution to add a image to a Word Document, like the UDF from Bid_Daddy.

Textreplacement and ImageInsert is working, I trie to add a Image to a TextBox but it wont work

I think its simple, but how to

Thanks a lot

Share this post


Link to post
Share on other sites

If you didn't want to use the UDF (which is a way cooler and smarter way... :P) you can copy the file to your clipboard (using _ClipPutFile) and then pasting it into an open word doc... :)

Share this post


Link to post
Share on other sites

If you didn't want to use the UDF (which is a way cooler and smarter way... :P) you can copy the file to your clipboard (using _ClipPutFile) and then pasting it into an open word doc... :)

Hi Bert, I tried the UDF and it works fine.

It should work like this:

Read a Excel Sheet, create a Word Doc, replace some Text and add a image into a TextBox ( centered in the Doc)

Add a image outside the TextBox is OK, but I can't get it into the TextBox

Share this post


Link to post
Share on other sites

Anybody a idea ??

Share this post


Link to post
Share on other sites

I was working on this, but got sidetracked somehow. I'll see if I can come up with an example sometime today.

Share this post


Link to post
Share on other sites

I was working on this, but got sidetracked somehow. I'll see if I can come up with an example sometime today.

Thanks in advance Big_Daddy

Share this post


Link to post
Share on other sites

Sorry it took me so long with the example, I got stuck on the text orientation problem.

#include <Word.au3>

;WdTextOrientation
Const $wdTextOrientationHorizontal = 0
Const $wdTextOrientationUpward = 2
Const $wdTextOrientationDownward = 3
Const $wdTextOrientationVerticalFarEast = 1
Const $wdTextOrientationHorizontalRotatedFarEast = 4
Const $wdTextOrientationVertical = 5

Global $iLeft = 50, $iTop = 50, $iWidth = 200, $iHeight = 200
$sFilePath = @ScriptDir & "\Test.doc"

_WordErrorHandlerRegister()
$oWordApp = _WordCreate($sFilePath, 1)
$oDoc = _WordDocGetCollection($oWordApp, 0)

; Left, Top, Width, Height, Anchor
$oShape = $oDoc.Shapes.AddCanvas($oWordApp.PixelsToPoints($iLeft), $oWordApp.PixelsToPoints($iTop), $oWordApp.PixelsToPoints($iWidth), $oWordApp.PixelsToPoints($iHeight))
; Orientation, Left, Top, Width, Height
;~ $oTextbox = $oShape.CanvasItems.AddTextbox($wdTextOrientationHorizontal, 1, 1, $oShape.Width - 1, $oShape.Height - 1) ; I would expect this to work.
$oTextbox = $oShape.CanvasItems.AddTextbox($wdTextOrientationVertical, 1, 1, $oShape.Width - 1, $oShape.Height - 1) ; This does work however.
; Get the range object of the textbox.
$oRange = $oTextbox.TextFrame.TextRange
; Insert a picture into the textbox.
_WordDocAddPicture($oDoc, @ScriptDir & "\test.jpg", False, True, $oRange)

Share this post


Link to post
Share on other sites

SUPER Thanks a lot :D:P

Share this post


Link to post
Share on other sites

Ahhh! Brilliant!

Thanks!

SUPER Thanks a lot :) :)

You're welcome, glad I was able to help.

Share this post


Link to post
Share on other sites

Sorry it took me so long with the example, I got stuck on the text orientation problem.

#include <Word.au3>

;WdTextOrientation
Const $wdTextOrientationHorizontal = 0
Const $wdTextOrientationUpward = 2
Const $wdTextOrientationDownward = 3
Const $wdTextOrientationVerticalFarEast = 1
Const $wdTextOrientationHorizontalRotatedFarEast = 4
Const $wdTextOrientationVertical = 5

Global $iLeft = 50, $iTop = 50, $iWidth = 200, $iHeight = 200
$sFilePath = @ScriptDir & "\Test.doc"

_WordErrorHandlerRegister()
$oWordApp = _WordCreate($sFilePath, 1)
$oDoc = _WordDocGetCollection($oWordApp, 0)

; Left, Top, Width, Height, Anchor
$oShape = $oDoc.Shapes.AddCanvas($oWordApp.PixelsToPoints($iLeft), $oWordApp.PixelsToPoints($iTop), $oWordApp.PixelsToPoints($iWidth), $oWordApp.PixelsToPoints($iHeight))
; Orientation, Left, Top, Width, Height
;~ $oTextbox = $oShape.CanvasItems.AddTextbox($wdTextOrientationHorizontal, 1, 1, $oShape.Width - 1, $oShape.Height - 1) ; I would expect this to work.
$oTextbox = $oShape.CanvasItems.AddTextbox($wdTextOrientationVertical, 1, 1, $oShape.Width - 1, $oShape.Height - 1) ; This does work however.
; Get the range object of the textbox.
$oRange = $oTextbox.TextFrame.TextRange
; Insert a picture into the textbox.
_WordDocAddPicture($oDoc, @ScriptDir & "\test.jpg", False, True, $oRange)

Using this example, how can I remove the Text Box line from the text box?

I know that in VBA I can write something like this to do the trick:

Activedocument.Shapes("Text Box 1").Select   
Selection.ShapeRange.Line.Visible = msoFalse

So, what is the line of code this example needs in order to acomplish this?

Thank you...

Share this post


Link to post
Share on other sites

Using this example, how can I remove the Text Box line from the text box?

I know that in VBA I can write something like this to do the trick:

Activedocument.Shapes("Text Box 1").Select   
Selection.ShapeRange.Line.Visible = msoFalse

So, what is the line of code this example needs in order to acomplish this?

Thank you...

Ok, I found the answer to my own question. To remove the textbox line frame, use the following line of code:

$oTextbox.Line.Visible = False

Hope this helps others...

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