Jump to content

Insert image to Word


Odilo60
 Share

Recommended Posts

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

Link to comment
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... :)

Link to comment
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

Link to comment
Share on other sites

  • Moderators

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)
Link to comment
Share on other sites

  • 2 weeks later...
  • 1 year later...

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

Link to comment
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...

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...