Jump to content
Sign in to follow this  
Nuro

Error at the end of script

Recommended Posts

Nuro

I have a script that runs a bunch of queries and then opens and runs an excel procedure that updates a bunch of reports based off of the query output. The whole process takes about an hour. At the end of hte excel proedure, it closes the file and leaves a blank desktop ready for the next day's run.

I'm running into a problem that after excel closes, autoit gets an error. It says....

Line 378 (File "\\(network path and script name)")

$oExcel.Application.Run("DailyAutomation")

$oExcel.Application.Run("DailyAutomation") Error

Error: The requested action with this object has fail.

Here is the end of the autoit script.

377 $oExcel = _ExcelBookOpen($TestFileDir & "Daily Updates Application.xls")

378 $oExcel.Application.Run("DailyAutomation")

379

380 WinWaitClose ("Microsoft Excel - Daily Updates Application")

381

382 Exit

Can someone help me? LInes 379 - 382 was my last attempt at fixing the error. I know you don't need the "exit" statement at the end of the script but I'm grasping for straws here. I could leave the file open and when the script runs the next day check to see if its open and if so, close it but I'd rather just close it without getting the error at the end.

Edited by Nuro

Share this post


Link to post
Share on other sites
PsaltyDS

The .xls file opens correctly and the "DailyAutomation" macro runs correctly?

My guess is that the AutoIt script goes on to the next line immediately, without waiting for the macro to finish, and does it so fast that the macro has not STARTED yet, which satisfies WinWaitClose() and goes on to exit - which closes out $oExcel while the macro is still running, causing an error.

If that is happening, all you need is a WinWait() to make sure the script sees the macro start before looking for it to close:

$oExcel = _ExcelBookOpen($TestFileDir & "Daily Updates Application.xls")
$oExcel.Application.Run("DailyAutomation")
WinWait ("Microsoft Excel - Daily Updates Application")
WinWaitClose ("Microsoft Excel - Daily Updates Application")
Sleep(1000)

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Nuro

I never thought about that. I'll give winwait a try and let you know. But yes. the marco runs fine and when excel closes, thats when the error pops up. The only problem is that at the beginning, all I had was the run portion of the script at the end. I didn't have the winwaitclose or exit and it still got the error even though the script should have been over as soon as it started the macro.

Edited by Nuro

Share this post


Link to post
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
Sign in to follow this  

×