I have just started using AppleScript and know very little. Basically, I need a script which conditionally formats the cells of a spreadsheet based on the content of each cell. I have started with a very basic code as an example, but I can’t seem to get the font color to change. Any tips? Thanks a lot!
tell application "Microsoft Excel"
tell range "a1" of active sheet
try
delete (every format condition)
end try
set newFormatCondition to make new format condition ¬
at end with properties {format condition type:¬
cell value, condition operator:operator equal, formula1:"hi"} ¬
tell font object of newFormatCondition
set {font color index} to {12}
end tell
end tell
end tell
You should really download the Excel2004AppleScriptRef.pdf from mactopia and browse the first chapters.
They might be helpful, and if that isn’t enough, you should try to search the forum here.
I just can’t get it to work. I’ve tried it with a bunch of different color indexes, I’ve used “colorIndex” rather than font color index and nothing seems to work. The script works when I use it to bold or italic the object, but not for color. Also, I’m using Excel 2008 rather than 2004… that may be the difference?
I am looking at this reference guide now from the mac website, maybe I can figure it out.
tell application "Microsoft Excel"
launch
tell range "a1" of active sheet
try
delete (every format condition)
end try
end tell
if get value of range "A1" is "hi" then
tell interior object of range "a1" of active sheet
set color index to 6
end tell
end if
end tell