I'm trying to open a very large excel file (*.xls) using applescript. The code is very simple, it looks like it is working, however after a few minutes I receive the following message:
Result: error "Microsoft Excel got an error: AppleEvent timed out." number -1712
Any idea about how to solve it? BTW using the automator doesn't work either.
Here's my code
tell application "Microsoft Excel"
activate
open "/Users/sergioguerra1/Desktop/Detektor/Etapa II/Reporte General.xls"
delay 300
end tell
Try wrapping the open command in a with timeout
block.
eg.
tell application "Microsoft Excel"
activate
with timeout of 3600 seconds
open "/Users/sergioguerra1/Desktop/Detektor/Etapa II/Reporte General.xls"
end timeout
end tell
This will override Applescripts default timeout of 2 mins, giving it longer to finish executing that command.
More info here in the AppleScript docs.
Conversely, if you are wanting to open your excel file/s without having to wait 2 minutes or longer ( eg 3600 secs) for a timeout to occur, then you may prefer to delibertely trigger the timeout sooner, and catch the error with "try" block.
I've found this problem occurs when I use the "linked tables" feature in excel, and the linked table is no longer accessable. Excel pops up a nasty dialog 1/2 way through the "open" command and just hangs till you type ESC twice ( or similar ) eg:
try
with timeout of 10 seconds
open some_excel_File
end timeout
on error -- excel timeout probably due to linked tables
-- if the file has "linked tables" we need to hit esc twice after opening it.
tell application "System Events"
repeat 2 times
key code 53
delay 3
end repeat
end tell
end try
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With