Selecting Multiple Sheets in Excel

Hello again,

I was wondering if there is a way to select multiple worksheets in Excel, then perform an action on multiple cells within each of those sheets. If I were doing this by hand, I would click on the first sheet’s tab, hold the shift, then click the last sheet’s tab, then type in the value in the cell of the top sheet. All of the cells in the same range “below” that that had been selected would also get the value entered. From what I’ve read, it may not be possible to do that in AppleScript. Here is my workaround:

set MonthList to {January, February, March, April, May, June, July, August, September, October, November, December}
repeat with i from 1 to 12
	set AccrueMonth to item i of MonthList
end repeat

on MonthlyZero(AccrueMonth)
	tell application "Microsoft Excel"
		set AccrueSheet to ("" & (AccrueMonth as text) & "")
		set formula of range "C1" of sheet AccrueSheet to 0
		set formula of range "B14" of sheet AccrueSheet to 0
	end tell
end MonthlyZero

It works as it is supposed to, but I was wondering if there is a way to address these cells in multiple cells more “directly.”


Tom Carlson


indeed there is took me a little bit to figure it out but I got it so here it is

tell application "Microsoft Excel"
	select sheets
	set formula of range "C1" to 1
	set formula of range "B14" to 0
end tell

Thank you mcgrailm. Do you know how to specify the sheets to be selected? Using your script selects all sheets in the workbook. Is there a way to select specific sheets, such as “January” through “December.” I’ve been experimenting, but can’t get it to do that yet.


Tom, I played around with this however I can’t seem to figure out how to select specific sheets:(


Same here. Thanks for trying.