Reputation: 3253
Excel 2003 had a simple ...interior.colorindex and only 56 numbers. But, this is changed with Excel 2010 for better control.
Now while developing a program.. which is supposed to copy a cell color (in VBA) and put the same color of the cell to an Excel Shape depending on the cell contents... i was lost with several different objects like this:
For the Cell:
Sheets("Config").Range("E1").Interior.ThemeColor = 10
Sheets("Config").Range("E1").Interior.TintAndShade = -0.249977111117893
For the Shape:
Activesheet.shapes("R3").fill.forecolor.objectthemecolor = 7
Activesheet.shapes("R3").fill.forecolor.brightness = 0.6
Activesheet.shapes("R3").fill.forecolor.schemecolor = 42
Activesheet.shapes("R3").fill.forecolor.tintandshade (and this doesn't even work)
Upvotes: 2
Views: 11957
Reputation: 88711
I have found a better simpler way which don't require all the above different naming..
All you need is:
range("b9").Interior.Color
which will return a long... like this for example: 682978 (of the hex color in decimal)
And, you can set the color for the shape like this:
.Shapes(xName).Fill.ForeColor.RGB = 682978 (some variable)
Other useful notes are:
range("h1").Interior.Color = rgb(0,123,124)
and, for printing in console
? rgb(0, 123, 124)
Upvotes: 1