Here’s the code, fairly std except for the save active workbook command - I’ve even tried save front workbook – help??:
on quit
tell application "Finder"
activate
beep
set dd to display dialog "Your Excel Spreadsheed has finished calculating." & return & return & ¬
"Do you wish to save it?" giving up after 120 with icon stop ¬
buttons {"Yes", "No"} default button "No"
if (gave up of dd is true) then
set response to "No"
else
set response to button returned of dd
end if
if (response is "Yes") then
tell application "Microsoft Excel"
activate
save active workbook
end tell
else
tell application "Microsoft Excel" to activate
end if
end tell
continue quit
end quit
Hi John.
if the active workbook already exists on disk this could be an alternative
close active workbook saving yes
if not
save workbook as active workbook filename "path:to:filename.xls"
or to get the Save as dialog
get save as filename
Stefan:
Thanks bunches, but here is what I have discovered:
-- "unsaved" dot remains in Close button, indicating not really saved??
get save as filename
-- continue quit doesn't seem to work, i.e., with closure,
-- another handler is called, which is really wierd??
close active workbook saving yes
-- "unsaved" dot in Close button disappears for a split second, only to reappear.
-- Also, AppleScript application stays open and has to be force-quit.
save workbook as active workbook filename gExcelDoc -- e.g., "My Spreadsheet"
I found the solution … place the saving code in a handler outside of the on quit handler. Then, the error -128 forces a successful saving of the Excel document, followed by a successful quitting of the Applet. By doing this, I really do not need a on quit handler at all.