Saving and closing MS Excel open windows ....

Hi,

I want to save and close all open windows in specific applications. I have found a easy way to do that in most apps, but MS Excel has a special behavior.

If I have 12 open windows in MS Excel, my normal script won’t work unless I repeat it many times as in this script:

tell application "System Events" to exists process "Excel"
if result then
	repeat 5 times
		try
			with timeout of 5 seconds
				tell application "Excel" to close every window saving yes
			end timeout
		end try
	end repeat
end if

Why does MS Excel need to repeat a statement that should do it all in one step ?

Thanks in advance.

Robert Lespérance

In Excel, a workbook can have many open windows. The MS site says that this should close all open workbooks.

tell application "Microsoft Excel"
	close every workbook saving yes
end tell

Hi mikerickson,

It is a good idea. Excel workbooks on my computer modifies the display of my different spreadsheets. I don’t know the reason why. I will stick with my script, but was wondering what was the reason for this behavior.

Thanks for helping.

Robert