ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Command Button Color Palette (https://www.excelbanter.com/excel-programming/415880-command-button-color-palette.html)

Greg in CO[_2_]

Command Button Color Palette
 
Hi All!

I have added several command buttons to my worksheet to run macros
triggering custom views to allow the users to only see the rows applicable to
the phase they are currently working (all in an effort to make the worksheet
easier on the eyes).

The header rows for each phase have a specific color, with the cells being
fille din using the palette in the Format Cells function.

When I go into the properties for the Command Button while in design mode,
Excel shows a similar color palette, but not with the exact same colors as
appear when coloring a cell. I want the button to be "Gold" as in the
regular Excel cell color palette, but the Command Button palette does not
have that color. The closest I can get is either pale yellow or pumpkin
orange. The orange has a code of &H000080FF&. Is there a way to get the
saem colors? Is there a way to get the code for the Gold color I am looking
for?

Thanks!
--
Greg

Rick Rothstein \(MVP - VB\)[_2625_]

Command Button Color Palette
 
I'm not sure if there is an easier way to do this, but the following will
work. First, go to a code window (any one will do) and copy/paste this code
into it...

'***************** START OF CODE *****************
Sub GetRGB()
Dim OldColorIndex As Long
Dim CellColor As Long
Const NewColorIndex As Long = 47
OldColorIndex = Range("A1").Interior.ColorIndex
Range("A1").Interior.ColorIndex = NewColorIndex
CellColor = CLng(Range("A1").Interior.Color)
Range("A1").Interior.ColorIndex = OldColorIndex
Debug.Print "Red: " & RGorB(CellColor, "R")
Debug.Print "Gree: " & RGorB(CellColor, "G")
Debug.Print "Blue: " & RGorB(CellColor, "B")
End Sub

Function RGorB(RGBvalue As Long, R_G_or_B As String) As Integer
Dim Exponent As Long
Exponent = InStr("RGB", UCase$(Left$(R_G_or_B, 1))) - 1
If Exponent = -1 Or RGBvalue < 0 Or RGBvalue 16777216 Then
RGorB = -1
Else
RGorB = RGBvalue \ 256 ^ Exponent Mod 256
End If
End Function
'***************** END OF CODE *****************

Change the NewColorIndex constant in the GetRGB subroutine to the ColorIndex
value you want to match and then run the GetRGB subroutine... it will print
out the RGB values for the ColorIndex you specified. Now, go to the
Properties Window for the CommandButton, click the down arrow for the
BackColor property and select the Palette tab. Now, right click any of the
16 white boxes at the bottom and type in the Red, Green and Blue values that
the above code printed out to the Immediate Window, then click the "Add
Color" button. Your CommandButton should now be colored with the same color
as the ColorIndex you specified.

Rick


"Greg in CO" wrote in message
...
Hi All!

I have added several command buttons to my worksheet to run macros
triggering custom views to allow the users to only see the rows applicable
to
the phase they are currently working (all in an effort to make the
worksheet
easier on the eyes).

The header rows for each phase have a specific color, with the cells being
fille din using the palette in the Format Cells function.

When I go into the properties for the Command Button while in design mode,
Excel shows a similar color palette, but not with the exact same colors as
appear when coloring a cell. I want the button to be "Gold" as in the
regular Excel cell color palette, but the Command Button palette does not
have that color. The closest I can get is either pale yellow or pumpkin
orange. The orange has a code of &H000080FF&. Is there a way to get the
saem colors? Is there a way to get the code for the Gold color I am
looking
for?

Thanks!
--
Greg




All times are GMT +1. The time now is 02:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com