Home | About | Log in | Get The Feed
Sharing the Wealth: Random Excel Tip #3

September

27

2006

More on color palettes today…

One of the problems with the previously discussed Excel color tip is that custom colors are not particularly portable. In other words, I can easily set up the custom palette on my computer but sharing that with you is a rigamorole. Instead of the color definitions being embedded in the Excel file, I’d have to give you a template file that you could import the palette from (yech!) every time you want to look at the report with my carefully chosen and designed colors.

This led me to the question of, can I store the color definitions in VBA? The answer is, no surprise, YES! I found the following snippet in a thread over on Mr. Excel.

Private Sub Workbook_Open()
Application.ScreenUpdating = False

ActiveWorkbook.Colors(35) = RGB(0, 115, 106) ‘ Teal
ActiveWorkbook.Colors(36) = RGB(255, 255, 153) ‘ Yellow
ActiveWorkbook.Colors(37) = RGB(52, 99, 175) ‘ Light Blue
ActiveWorkbook.Colors(38) = RGB(244, 154, 193) ‘ Pink
ActiveWorkbook.Colors(40) = RGB(255, 204, 153) ‘ Tan

Application.ScreenUpdating = True
End Sub

Yeah! Now my custom colors will load whenever the workbook is opened. AWESOME. Uh Oh, wait, Excel refers to each of the fifty-six colors by an index number and by the way, the index number has absolutely nothing to do with the color’s position in the palette grid (available from the format menu).

Mr. Excel to the rescue again. In this thread, I found a cool little function that lists our colors 1-56 in color coordinated cells.

Cool Little Function: (oops I had the wrong function in there orginally - sometimes I’m my worst editor)

Sub colors()
For i = 1 To 56
With Cells(i, “A”)
.Interior.ColorIndex = i
.Value = i
.HorizontalAlignment = xlCenter
.Font.Color = vbWhite
.Font.Bold = True
End With
Next i
End Sub

The only missing piece is the original RGB value. So, with a little work in Photoshop, I created the following matrix:

excel_color_palette.gif

The number in the top right corner of each color block represents the Index number that Excel assigns to that color (see what I mean about it not really being arranged in a particularly useful way? It looks like they messed up a couple times and put some of the numbers in order).

In the lower left hand (ish) corner of each block is its RGB value.

The first five rows represent Excel’s ’standard color palette’ while the sixth and seventh rows represent the colors for chart lines and fills respectively.

Whew! Now I have a reference map for building out that first macro (I know which colors are which in the Excel palette when I change a particular index’s RGB value) and I have that Macro for making the custom color choices portable.

Are there other better solutions for making custom color palettes (in Excel) portable? Let us know how you’ve gotten around this issue

By the way, I am well aware that this tip is another rehash of information found elsewhere - but why should I have to go through another 2 or 3 hours of searching pain if I need this again and more importantly why should you?

« Previous Post » Next Post

5 Responses to “Sharing the Wealth: Random Excel Tip #3”


This is just what I need, but I’m a bit of a novice so I don’t understand how to do it. I don’t understand the coding you show. Is there a simple keystroke guide to setting up the “Classic” 40/56 color palette for use as the default in Excel 2007? This is really important stuff and I need it badly but I really don’t understand the above presentation — too technical for me.

Don


Don,
I just spent the last hour scouring the net and haven’t found a solution to your question. Mostly because I think most Excel users like the new palette better - it has nearly unlimited options and the default colors in the palette are better thematically than in previous versions.

-Clint


[...] one of these. According to Wordpress, the last "Sharing the Wealth" post was published on September 27, 2006 - discussing how to store color assigments in VBA. Guess I haven’t been doing a lot of Excel [...]


Don -

The information in this post works for Excel versions 97 through 2003. The Excel 2007 color system is pretty much incompatible with prior versions. I’m still in the process of getting my head around it. There are a couple of very good posts by Tony Jollans in the Professional Office Developers Association blog that I’ve found very helpful:

Colours in Word 2007, Parts 1 and 2
http://proofficedev.com/blog/2007/08/
http://proofficedev.com/blog/2007/10/10/

It says Word 2007, but Office 2007 uses the same color methodology across all applications.


Jon,
thanks for the comment and information. Hopefully Don will be back and will see your note.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>