NassauSky Posted September 24, 2023 Share Posted September 24, 2023 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 More sharing options...
Solution ioa747 Posted September 25, 2023 Solution Share Posted September 25, 2023 #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 More sharing options...
NassauSky Posted October 12, 2023 Author Share Posted October 12, 2023 (edited) @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 October 12, 2023 by NassauSky Link to comment Share on other sites More sharing options...
NassauSky Posted October 12, 2023 Author Share Posted October 12, 2023 I had the wrong pixels to points calculation in my old script. Turns out 1 pixel is 0.75 points. That answered the question. I'm going to play with the layout now and see how it all works out. Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now