Jump to content

Setting Word Picture to behind text


NassauSky
 Share

Go to solution Solved by ioa747,

Recommended Posts

Anyone have experience with inserting a word picture behind text? I am not exactly sure what the problem is in the code:

 

;Add Image
      ; Add shape object
        $oShape = $oDoc.Shapes.AddCanvas($oWord.PixelsToPoints($iLeft), $oWord.PixelsToPoints($iTop), $oWord.PixelsToPoints($iWidth), $oWord.PixelsToPoints($iHeight))

      ; Orientation, Left, Top, Width, Height
        $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.
        $oLogo = _Word_DocPictureAdd($oDoc, $WordLogo, False, True, $oRange)
        $oLogo.LockAspectRatio = True
        $oLogo.Width = 300
        $oLogo.WrapFormat.Type = $wdWrapBehind
        $oTextbox.Line.Visible = False

 

Link to comment
Share on other sites

  • Solution

 

#include <MsgBoxConstants.au3>
#include <Word.au3>

; C:\Program Files (x86)\AutoIt3\Examples\Helpfile\   _Word_DocPictureAdd.au3
Local $sDir = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 2, -1) - 1) & "\Examples\Helpfile"
;----------------------------------------------------------------------------------------

; Create application object
Local $oWord = _Word_Create()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocPictureAdd Example", _
        "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Open the test document
Local $oDoc = _Word_DocOpen($oWord, $sDir & "\Extras\Test.doc", Default, Default, True)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocPictureAdd Example", _
        "Error opening '.\Extras\Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

; Add shape object
Local $oShape = $oWord.ActiveDocument.Shapes.AddPicture($sDir & "\Extras\Screenshot.png", False, True, 0, 35, 169, 32)
;AddPicture(FileName As String, [LinkToFile], [SaveWithDocument], [Left], [Top], [Width], [Height], [Anchor]) As Shape

$oShape.ZOrder(5) ;msoSendBehindText=5

;~ https://learn.microsoft.com/en-us/office/vba/api/office.msozordercmd
;~ msoBringForward         2    Bring shape forward.
;~ msoBringInFrontOfText   4    Bring shape in front of text. Used only in Microsoft Word.
;~ msoBringToFront         0    Bring shape to the front.
;~ msoSendBackward         3    Send shape backward.
;~ msoSendBehindText       5    Send shape behind text. Used only in Microsoft Word.
;~ msoSendToBack           1    Send shape to the back.

 

I know that I know nothing

Link to comment
Share on other sites

  • 3 weeks later...

@ioa747 Sorry I've been busy and had to switch projects so I just had time to test.   That code gave me ideas. How come when I run that test code, the resulting width of the image in the word doc is greater than 169 and it looks around 225 pixels wide.

Thanks!

Edited by NassauSky
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...