Ugh, I’ve tried alot of variations and combed the Excel 2004 guide and dictionary, still can’t figure this out…
I want to be able to change the fill color of the active cell, in this case, to red.
activate object cell currentRow of column currentColumn
set color index of interior of selection to 3
set pattern of interior of selection to solid
The first line selects/activates the cell I want to color. That should work, been working in other parts of the script. The second and third line are the way it was done pre-2004 versions of Excel.
Excel seems to use both Color Index and RGB Color as ways to define color, but the examples given apply to drawn objects, not cells. I’ve tried using back color of fill format of active cell but not sure how to tell it the color (tried a number of different ways).
in Excel 2004 a cell has an interior object
Properties of interior object are color index and pattern.
The solid constant of pattern is called pattern solid
tell application "Microsoft Excel"
tell interior object of cell currentRow of column currentColumn
set color index to 3
set pattern to pattern solid
end tell
end tell
I had a feeling there was an “object” I was missing. The new Excel uses more sub-objects rather than the older Excel exposing attributes all at the top level. Still getting the hang of that.
An interior object has both a color and a color index properties.
The color is an RGB value and the color index is a number (plus the constant color index none).
This script makes the interior of the active cell red, twice.
tell application "Microsoft Excel"
set myInterior to interior object of active cell
set color index of interior object of active cell to 3
set color of myInterior to {255, 0, 0}
end tell
This may have changed in 2008, but prior to that setting the color of an interior would not nessesarily result in the cell being colored with the RGB value given, it would result in the closest value from the color pallett (the 56 options for color index) being applied to the cell.