Macro dont save my Exel document, sometimes..

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
AnJen1a
Newbie
Posts: 2
Joined: Mon Jun 04, 2007 6:42 am

Macro dont save my Exel document, sometimes..

Post by AnJen1a » Mon Jun 04, 2007 6:50 am

Hi

My macro do not save my Exel document when i run it. 1 out of 10 times its just stop running. Else it works fine.

Sample of code:

setfocus>Microsoft Excel*
wait>0.5
setfocus>Microsoft Excel*
press alt
press f4
send>j
release alt
WaitWindowClosed>Microsoft Excel*

If you have any idea of why this happend, please make a reply.

AnJen1a
Newbie
Posts: 2
Joined: Mon Jun 04, 2007 6:42 am

Post by AnJen1a » Mon Jun 04, 2007 7:30 am

The problem is that some times it just stops here, and do not exit Exel. The macro simply just stop running. Even though there more code to run. The rest of the macro, will only run when Exel is closed and the document is saved.

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Jun 04, 2007 1:36 pm

I don't know what is causing your intermittent problem but I suspect that 1/2 second is sometimes not long enough for Excel to come into focus. You could try making the wait longer or you could make the script loop so that it will wait the correct amount of time. Add a timeout value (see help for WaitWindowClosed) When/if the window does not close within the specified timeout, run the close process again.

Code: Select all

Label>Retry
setfocus>Microsoft Excel*
wait>0.5
setfocus>Microsoft Excel*
press alt
press f4
send>j
release alt
Let>WW_TIMEOUT=1
WaitWindowClosed>Microsoft Excel*
If>WW_RESULT=FALSE,Retry
If you find that Excel sometimes does not close at all, you might need to do some error checking. Add a counter to the loop and after the loop has run a certain number of times, send your self an email and do something to end the process.

Code: Select all

Label>Retry
Add>k,1
If>k=11,ExcelCloseError
setfocus>Microsoft Excel*
wait>0.5
setfocus>Microsoft Excel*
press alt
press f4
send>j
release alt
Let>WW_TIMEOUT=2
WaitWindowClosed>Microsoft Excel*
If>WW_RESULT=FALSE,Retry

Goto>EndOfError
Label>ExcelCloseError
Let>server=mail.yourserver.com
Let>[email protected]
Let>name=Excel Error
Let>subject=Excel Error
Let>bod=Cannot close Excel
Let>[email protected]
SMTPSendMail>recip,server,from,name,subject,bod,
MDL>Cannot close Excel
Goto>a label of your choice
Label>EndOfError

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts