mojo8472 mojo8472 - 3 months ago 6
AppleScript Question

Iterating Applescript over all sheets in an Excel workbook

I've done some searching, but can't seem to find how to get my Applescript to iterate for each sheet in an Excel workbook. At the moment I'm just telling the script to repeat indefinitely and manually click through the sheets, which isn't ideal!

This is what I want done for every sheet in the workbook, any ideas on how I can achieve this?

tell application "Microsoft Excel"
set rangeVoltage to value of range "A11:A110"
set value of cell "D11:D110" to rangeVoltage
set value of cell "E11" to "=B11*1000"
fill down range "E11:E110"
set value of cell "D10" to "Voc (V)"
set value of cell "E10" to "Isc (mA)"
end tell

Answer

Try:

tell application "Microsoft Excel"
    set mySheets to every sheet of active workbook
    repeat with aSheet in mySheets
        tell aSheet
            set rangeVoltage to value of range "A11:A110"
            set value of cell "D11:D110" to rangeVoltage
            set value of cell "E11" to "=B11*1000"
            fill down range "E11:E110"
            set value of cell "D10" to "Voc (V)"
            set value of cell "E10" to "Isc (mA)"
        end tell
    end repeat
end tell