Santana Posted October 14, 2009 Share Posted October 14, 2009 Hi all, The following is a function that creates a bunch of MS Word documents and then convert them to .pdf it also deletes the word document after the pdf is created (I only need the pdf version of the file) func print($getfile) if FileExists($iresultfolder & "\TDBK3077_" & $p -1 & ".doc") then FileDelete($iresultfolder & "\TDBK3077_" & $p -1 & ".doc") $oWordApp = _WordCreate ($iresultfolder & "\TDBK3077_" & $p & ".doc", 0,0,0) $oDoc = _WordDocGetCollection ($oWordApp, 0) $oShape = _WordDocAddPicture ($oDoc, $sPath & $getfile, 0, 1) If Not @error Then $oShape.Range.InsertAfter (@CRLF) _WordDocPrint ($oDoc) ;sleep(500) ProcessWaitClose("Acrobat.exe") _WordDocClose ($oDoc) $p +=1 EndFunc The problem is that most of the time I get the following error and I have to run the script two or three times, then it works fine. ERROR: C:\Program Files\AutoIt3\Include\Word.au3 (366) : ==> The requested action with this object has failed.: $o_doc = $o_object.Documents.Add ($s_Template, $f_NewTemplate, $i_DocumentType) $o_doc = $o_object.Documents.Add ($s_Template, $f_NewTemplate, $i_DocumentType)^ ERROR Can anyone give me a hint of what am I doing wrong? Thanks Just another special date with a different challenge Link to comment Share on other sites More sharing options...
IndyUK Posted October 14, 2009 Share Posted October 14, 2009 ERROR: C:\Program Files\AutoIt3\Include\Word.au3 (366) : ==> The requested action with this object has failed.: $o_doc = $o_object.Documents.Add ($s_Template, $f_NewTemplate, $i_DocumentType) $o_doc = $o_object.Documents.Add ($s_Template, $f_NewTemplate, $i_DocumentType)^ ERROR Can anyone give me a hint of what am I doing wrong? Thanks I think it's because your script is trying to process the document before the whole file is available for opening. I do a very similar task with MS Office and found that if the document hadn't finished copying to the input folder, I would get that error. Try this function code: If _CheckFileAvailable($SourceFile) <> -1 Then ;check source file is available for reading/conversion ... ... ... EndIf Func _CheckFileAvailable($File) $File = FileOpen($File, 0) FileClose($File) Return $File EndFunc Link to comment Share on other sites More sharing options...
Santana Posted October 14, 2009 Author Share Posted October 14, 2009 Thanks. I'll give it a try Just another special date with a different challenge Link to comment Share on other sites More sharing options...
Santana Posted October 16, 2009 Author Share Posted October 16, 2009 Tried that. Same error. any other input??? Thanks Just another special date with a different challenge Link to comment Share on other sites More sharing options...
JoKurt Posted November 25, 2009 Share Posted November 25, 2009 (edited) modify your word.au3 - udf Function: _WordDocAdd(...) Line: ~37x $o_doc = $o_object.Documents.Add ($s_Template, $f_NewTemplate, $i_DocumentType) To: If $o_object.Application.Version () <= 8 Then ;MsgBox(0,"WordVersion " & $o_object.Application.Version (), "ups... Word 97 installed?") $o_doc = $o_object.Documents.Add ($s_Template, $f_NewTemplate);, $i_DocumentType) Else $o_doc = $o_object.Documents.Add ($s_Template, $f_NewTemplate, $i_DocumentType) EndIf Edited November 25, 2009 by JoKurt 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