pdm Posted December 10, 2013 Posted December 10, 2013 I'm using WordEx 1.3 with AutoIt 3.3.8.1, Word 2010, Win 7/64 on a core i5-machine. When i run the following code, i do get what i expect for now: Just a copy of my Template file stored under a different name. #include <..\WordEX\WordEx.au3> const $ERR_NONE = 0 const $ERR_NOWORD = 1001 const $ERR_NOTPL = 1002 const $ERR_NOOUT = 1003 const $ERR_NOCMD = 1004 const $ERR_INCMD = 1005 func l_createtpl_cmd ($arg_tpl, $arg_out, $arg_cmd, $arg_vis) local $err, $oWord1App, $oDoc1 $err = $ERR_NONE $oWord1App = _Word_Create ($arg_vis, true) If @error = 0 Then $oDoc1 = _Word_DocAdd ($oWord1App, $wdNewBlankDocument, $arg_tpl, false) If @error = 0 Then ;work on it ;save the result msgbox (0, "WordTest", "save as "& $arg_out, 0) _Word_DocSaveAs ($oDoc1, $arg_out, $wdFormatTemplate) if @error <> 0 Then $err = $ERR_NOOUT endif else $err = $ERR_NOTPL endif _Word_Quit ($oWord1App) else $err = $ERR_NOWORD endif return $err endfunc l_createtpl_cmd (@ScriptDir &"\test.dot", @ScriptDir &"\out.dot", "any command", true When i take the MessageBox away or answer it before the Word-Document appears, the Word_DocSaveAs function tells me that it was not successfull. If Word runs invisible, the timimg of my operations seems to be alright. Is there a way to tell WordEx to synchronize with it's Word-Window or is WinWaitActive the only workaround? Please give me some advice...
water Posted December 10, 2013 Posted December 10, 2013 I once had a problem with a badly written add-in. Could you please deactivate your add-ins and try again? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
pdm Posted December 10, 2013 Author Posted December 10, 2013 Thanks, water, but i have no active Add-Ins...
water Posted December 10, 2013 Posted December 10, 2013 Which version of Word do you run? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
pdm Posted December 10, 2013 Author Posted December 10, 2013 I'm using Word 2010 (as written in the first posting)
pdm Posted December 10, 2013 Author Posted December 10, 2013 By the way, my template-file contains a linked picture which is located on a network drive. This is rather slow from my HomeOffice. That is why it takes so long to open up. But this may not lead to an error, since this could always happen in the production environment. How can i test the existence of the displayed document? WinWait doesn't work since the Word-Window is already visible, but not the contents of the copied template file. IsObj ($oDoc1) returns true after _Word_DocAdd, but i found no property to test the ready state. All attempts referencing properties with $oDoc1 lead to Errors aborting AutoIt. If i wait long enough to let the contents appear, $oDoc1 works as expected without reloading it! The object seems to be updated with the appearance of the Document content.
water Posted December 11, 2013 Posted December 11, 2013 Could you create a template without the picture so we know the picture causes the problem? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
water Posted December 11, 2013 Posted December 11, 2013 I'm using Word 2010 (as written in the first posting) Sorry, missed that My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
pdm Posted December 11, 2013 Author Posted December 11, 2013 I removed the picture from the template so it loads much faster and my example works so far, like it does with an invisible word-window. But this doesn't solve the timing problem when there actually are references to external objects. I had similiar problems with the Standard Word.au3. Of course i can turn the window invisible while loading the template and turn it on whenever i need some optical feedback for testing purposes. But when can i turn it back on without running into the same errors? Ok, while testing, i can insert some sleep-statements. But i'm not really happy when things depend on weak timings.
pdm Posted December 11, 2013 Author Posted December 11, 2013 I changed the code to load the template invisible and turning the visibility on afterwards: expandcollapse popup#include <..\WordEX\WordEx.au3> #include <array.au3> const $TITLE = "CheckWord" const $ERR_NONE = 0 const $ERR_NOWORD = 1001 const $ERR_NOTPL = 1002 const $ERR_NOOUT = 1003 const $ERR_NOCMD = 1004 const $ERR_INCMD = 1005 func _msg ($msg, $to = 0) msgbox (0, $TITLE, $msg, $to) EndFunc func _con ($txt, $eol = @CRLF) ConsoleWrite ($txt & $eol) ;_msg ($txt & $eol, 1) EndFunc #include <..\WordEX\WordEx.au3> #include <array.au3> const $TITLE = "CheckWord" const $ERR_NONE = 0 const $ERR_NOWORD = 1001 const $ERR_NOTPL = 1002 const $ERR_NOOUT = 1003 const $ERR_NOCMD = 1004 const $ERR_INCMD = 1005 func _msg ($msg, $to = 0) msgbox (0, $TITLE, $msg, $to) EndFunc func _con ($txt, $eol = @CRLF) ConsoleWrite ($txt & $eol) ;_msg ($txt & $eol, 1) EndFunc func l_createtpl_cmd ($arg_tpl, $arg_out, $arg_cmd, $arg_vis) local $err, $oWord1App, $oDoc1 $err = $ERR_NONE $oWord1App = _Word_Create (0, true) If @error = 0 Then $oDoc1 = _Word_DocAdd ($oWord1App, $wdNewBlankDocument, $arg_tpl, false) If @error = 0 Then if $arg_vis then sleep (500) $oWord1App.visible = $arg_vis endif ;work on it ;save the result ;_msg ("save as "& $arg_out &"...caption=<"& $oWord1App.caption &"> err="& @error &", ext="& @extended) _Word_DocSaveAs ($oDoc1, $arg_out, $wdFormatTemplate) if @error <> 0 Then $err = $ERR_NOOUT endif else $err = $ERR_NOTPL endif _Word_Quit ($oWord1App) else $err = $ERR_NOWORD endif return $err endfunc exit l_createtpl_cmd (@ScriptDir &"\test.dot", @ScriptDir &"\out.dot", "any command", true) and this runs so far. When there are problems i will vary the value of the sleep-statement. As stated above, i'm not completly happy with it, but i can go on... Thank you, water, for thinking it through!
water Posted December 11, 2013 Posted December 11, 2013 Next I would check if we can list the picture objects and wait until the picture has loaded. While 1 For $oInlineShape In $oDoc.InlineShapes ; Don't know which property to check right now. Maybe $oInlineShape.LinkFormat.SourceName or something similar. If $oInlineShape.LinkFormat.SourceName = "xxx" Then ExitLoop 2 Sleep(100) Next WEnd My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
water Posted December 11, 2013 Posted December 11, 2013 Or maybe property $oDoc1.AttachedTemplate is only set when the template has successfuuly been loaded. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
pdm Posted December 12, 2013 Author Posted December 12, 2013 Sorry, water, it only shows Error: The requested action with this object has failed. Right after _Word_DocAdd, the property $oDoc1.AttachedTemplate returns an empty string, but after a while the property seems to disappear and lead to the error written above. Seems to be a very strange behaviour!
water Posted December 12, 2013 Posted December 12, 2013 Will need to test. But as I'm on vacation quite soon it will take some time ... My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
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