John Walkenbach Color Palette (Repost)

E

ExcelMonkey

This is a repost. I posted this yesterday but did not describe it properly.

I am using the JW color palette. I am using it to do the following:

1) Pass a color from palette to the backcolor property of a button on a
userform
2) test to see if font color in specific cell matches backcolor property of
button

Firstly, when I call up the palette, most colors pass correctly to the
button on the userform. However the top left color (Black) will not pass to
the form. When I drag the cursor over the color black, the JW form tells me
that its RGB color is:

0 0 0

Why will this not turn the button black?

Secondly, in situations where the color passes correctly to the button, the
test to see if font color = button back color fails. For example, when I
pass red to the button (RGB(255,0,0)), the button turns red. However my test
for red font does not seem to work. The procedure is:

Public Function CellFontHasColour(rng As Range)
If rng.Font.Color = FontColorColBtn.BackColor Then
CellFontHasColour = True
End If
End Function

Yet in my immediate window I get:
?rng.Font.Color
255

?FontColorColBtn.BackColor
12632256

My font is clearly red as illustratd by the 255. Yet my BackColor property
of the button which I clearly passed red to now says 12632256.

I must admit I am really struggling with the whole colour issue in VBA.

Thanks
 
J

Jim Rech

I don't know why your button's backcolor isn't behaving but this code, which
shows how to convert a Color value to its RGB constituents might help your
debugging:

Sub ReturnRGB()
Dim r As Byte, g As Byte, b As Byte
Dim x As Long
x = 12632256
LongToRGB x, r, g, b
MsgBox "r = " & r & Chr(10) & "g = " & g & Chr(10) & "b = " & b
End Sub

Sub LongToRGB(lColor As Long, r As Byte, g As Byte, b As Byte)
r = CByte(lColor And &HFF&)
g = CByte((lColor And &HFF00&) \ &HFF&)
b = CByte((lColor And &HFF0000) \ &HFFFF&)
End Sub


--
Jim
| This is a repost. I posted this yesterday but did not describe it
properly.
|
| I am using the JW color palette. I am using it to do the following:
|
| 1) Pass a color from palette to the backcolor property of a button on a
| userform
| 2) test to see if font color in specific cell matches backcolor property
of
| button
|
| Firstly, when I call up the palette, most colors pass correctly to the
| button on the userform. However the top left color (Black) will not pass
to
| the form. When I drag the cursor over the color black, the JW form tells
me
| that its RGB color is:
|
| 0 0 0
|
| Why will this not turn the button black?
|
| Secondly, in situations where the color passes correctly to the button,
the
| test to see if font color = button back color fails. For example, when I
| pass red to the button (RGB(255,0,0)), the button turns red. However my
test
| for red font does not seem to work. The procedure is:
|
| Public Function CellFontHasColour(rng As Range)
| If rng.Font.Color = FontColorColBtn.BackColor Then
| CellFontHasColour = True
| End If
| End Function
|
| Yet in my immediate window I get:
| ?rng.Font.Color
| 255
|
| ?FontColorColBtn.BackColor
| 12632256
|
| My font is clearly red as illustratd by the 255. Yet my BackColor
property
| of the button which I clearly passed red to now says 12632256.
|
| I must admit I am really struggling with the whole colour issue in VBA.
|
| Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top