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.
Macro dont save my Exel document, sometimes..
Moderators: JRL, Dorian (MJT support)
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.
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
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
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