I'm still trying to figure out how to set the background color, draw
grids, etc. If you or anyone else figures out how to do this please
let me know!
I've never done any of this sort of thing in Excel (in the UI). But I can
see from the Dictionary how it's likely to work.
You haven't made clear if you're looking for the background color of a cell
(or range), or of a shape. I'll assume a cell.
This gets rather arcane. You'll notice that cell and range have an 'interior
object' property of type 'interior'. If you look long and hard, you'll find
an 'interior' class buried deep in the Chart Suite, of all places. It has a
'color' property, which is of type RGB color. Now RGB color is a standard
AppleScript type, which is a list of three integers between 0 and 65535 (2 ^
16) - 1. But _this_ RGB value seems to be the Microsoft VBA variety - a list
of three integers between 0 and 255. I'll report this as a bug. (You can
convert between the two types by squaring or getting the square root of each
integer.)
First I colored one cell D5 a shade of teal in Format/Cells. This works:
tell application "Microsoft Excel"
set theCell to cell "D5"
set theInterior to interior object of theCell
set b to color of theInterior
end tell
--> {128, 249, 111}
Or you can learn the table of color indices, I suppose, and use 'color
index':
tell application "Microsoft Excel"
set theCell to cell "D5"
set theInterior to interior object of theCell
set b to color index of theInterior
end tell
--> 33
You can set the color too. Here I set the same background color for the
whole used range:
tell application "Microsoft Excel"
set color of interior object of used range of active sheet to {128, 249,
111}
end tell
-- except that turned it green! There's a bug here somewhere.
tell application "Microsoft Excel"
set color index of interior object of used range of active sheet to 33
end tell
This worked correctly.
(I tried squaring the integers, but that resulted in a different darker
blue.)
So you'd better get the color index of all the colors you're interested in
and use those.
If you're dealing with shapes (Drawing Suite) , which can be made 'at' a
worksheet with properties {auto shape type: , left position: , top: ,
fill format: } , you can set the back color of the fill format (Drawing
Suite) to an RGB color.
You'll see in the Table Suite that you can add a border to a cell or range
by using the command 'border around':
border around: Adds a border to a range and sets the color, line style, and
weight properties for the new border.
border around range
[line style continuous/dash/dash dot/dash dot dot/dot/double/slant
dash dot/line style none] -- The line style for the border.
[weight border weight hairline/border weight medium/border weight
thick/border weight thin] -- The border weight.
[color index color index automatic/color index none/a color index
integer] -- The border color, as an index into the current color palette.
[color RGB color] -- The border color, as an RGB value.
which has all the options you need. It's very strange that you can then 'get
border' range, although range itself has no border property or elements.
Still, this should work. I'll look into it.
There's also a 'border' class in the Excel Suite, but only checkboxes,
option (boxes) ad text boxes seem to have this type of border. (And text
perhaps.) 'get border' command can get these too.
--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <
http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <
http://macscripter.net/scriptbuilders/>
Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.
PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.