« We Got Death Star | Main | Repaint Cells Excel Macro »

October 08, 2002

Paint Custom Color Excel Macro

This macro will paint the selected area a custom color.Macro will prompt you for an html color code. Use 16 bit color codes (FFFFFF=white). Macro will then prompt you for a palette index number (1-56, 17-32 are used for chart colors).

You can see a nice HTML Color Wheel here: http://www.visibone.com/color/hexagon_800.gif (web safe colors only, but a good starting point)
Here are some others from that site:

http://www.visibone.com/color/poster4x.html
http://www.visibone.com/color/card_800.gif


And here is an applet that lets you play with colors:
http://www-students.biola.edu/~brian/csapplet.html

Also:If you’ve worked hard to get your color palette the way you want it you can save the file with the palette as the default template. That way, every time you start a new Excel file, your color palette will be available. Here’s how:
1.    Press F12 to open the Save As dialog box.
2.    Select Template from the Save as type drop-down list.
3.    Navigate to the c:\program files\microsoft office\office\xlstart folder
4.    In the File name box, name the file book (don’t type an extension).
Click Save.

Sub PaintCustomColor()
    htmlcolorcode = Application.InputBox(prompt:="Enter HTML Color Code:", Type:=2)
    paletteslot = Application.InputBox(prompt:="Which palette slot should be used (17-32 are chart colors):", Type:=1)
    If Len(htmlcolorcode) <> 6 Then
        MsgBox ("HTML color code must be formatted hhhhhh, like F0CC33.")
    ElseIf paletteslot < 1 Or paletteslot > 56 Then
        MsgBox ("Invalid palette. Choose between 1")
    Else
        s_red = Left(htmlcolorcode, 2)
        s_green = Mid(htmlcolorcode, 3, 2)
        s_blue = Right(htmlcolorcode, 2)
        ActiveWorkbook.Colors(paletteslot) = RGB(Val("&H" & s_red), Val("&H" & s_green), Val("&H" & s_blue))
        If Not Selection Is Nothing Then
            Selection.Interior.ColorIndex = paletteslot
        End If
    End If
End Sub

Posted by Chris at October 8, 2002 04:00 PM

Subscribe to this entry:   Email address:   

Trackback Pings

TrackBack URL for this entry:
http://www.christulino.com/cgi-bin/mt/mt-tb.cgi/32

Comments

I have found this very useful when I wanted to demo excel sheet with custom colors. Appreciate your help.

-A

Posted by: Aditya Agarkar at October 22, 2003 03:10 PM