Kohr Posted September 28, 2006 Posted September 28, 2006 I am using the Microsoft Word Automation UDF Library for AutoIt3 (Word.au3) library to save .png files to a word document. The following code works great. #include <Word.au3> $oWordApp = _WordCreate ("", 0, 0) $oDoc = _WordDocGetCollection ($oWordApp, 0) $sPath = "C:\Program Files\Temp\" $file = "MWSnap.png" $oShape = _WordDocAddPicture ($oDoc, $sPath & $file, 0, 1) _WordDocSaveAs ($oDoc, @DesktopDir & "\WordOutput.doc") _WordQuit ($oWordApp) The following code will give console messages "--> Word.au3 Warning from function _WordDocOpen (The specified file does not exist, but we will attempt to create it.)" and "--> Word.au3 Info from function _WordDocOpen (The specified file was created successfully.)" when it is 1st run (without the file existing so I believe these messages are normal). The issue is that the picture is not in the word document. All other times I run the code I do not receive any console errors and the picture never gets inserted. The only thing that is different is the way I am using _WordCreate and the function used to save the file. Any help would be appreciated. #include <Word.au3> $oWordApp = _WordCreate (@DesktopDir & "\WordOutput.doc", 0, 0) $oDoc = _WordDocGetCollection ($oWordApp, 0) $sPath = "C:\Program Files\Temp\" $file = "MWSnap.png" $oShape = _WordDocAddPicture ($oDoc, $sPath & $file, 0, 1) _WordDocSave ($oDoc) _WordQuit ($oWordApp) Kohr AutoIt LinksAutoIt CrapsGrid_PixelSearchAdvancedPixelGrab
Moderators big_daddy Posted September 28, 2006 Moderators Posted September 28, 2006 Much better explanation! Let me do some testing/troubleshooting and hopefully I'll have something for you later today.
Moderators big_daddy Posted September 28, 2006 Moderators Posted September 28, 2006 This wasnt too hard to figure out. The problem is with the way I initially create the file if it doesn't exist. It is created as a text file not a word document; this causes _WordDocSave to drop anything that is not plain text. A quick word around is to use _WordDocSaveAs function with only the first parameter, which will save it as a word document. The example below should solve the problem. #include <Word.au3> $oWordApp = _WordCreate (@DesktopDir & "\WordOutput.doc", 0, 0) $oDoc = _WordDocGetCollection ($oWordApp, 0) $sPath = "C:\Program Files\Temp\" $file = "MWSnap.png" $oShape = _WordDocAddPicture ($oDoc, $sPath & $file, 0, 1) _WordDocSaveAs ($oDoc) _WordQuit ($oWordApp)
Kohr Posted September 28, 2006 Author Posted September 28, 2006 Thanks Big Daddy. This works great. Now its time to try and impliment your functions . Kohr AutoIt LinksAutoIt CrapsGrid_PixelSearchAdvancedPixelGrab
Moderators big_daddy Posted September 28, 2006 Moderators Posted September 28, 2006 No problem, glad I was able to help.
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