...I am not sure how I convert my RGB colour to the colour code that activeX uses. Eg.
Do you know what this colour coding is called? If I knew that, perhaps I could find a converter. Thanks
Office and VBA are
notoriously confusing when it comes to colors, mainly because there are too many ways to specify a color.
The easiest way to specify colors in VBA is with the
color constants: The easiest way to specify colors in VBA is with the color constants:
vbBlack vbRed vbGreen vbYellow vbBlue vbMagenta vbCyan vbWhite
&H80000018&
is an example of Excel's version of a hexadecimal color code, similar to HTML color codes used in web design (with the extra 2 digits to specify transparency).
- The
&H
indicates that it's a hex code. Hexadecimal digits range from 0 to 9 and then A-F (for 10 to 15)
- The next 2 digits specify "Red" between 00 and FF which is 0 and 255. (128 in the case of the code mentioned above)
- The following 2 digits are "Green" between 00 and FF which is 0 to 255 (0 in this case)
- The following 2 digits are "Blue" between 00 and FF which is 0 to 255 (0 in this case)
- The last 2 digits before the closing
&
indicate the transparency or "opacity" from 0 to 255 (24 in this case)
To convert between hexadecimal and decimal ("regular") numbers you could use Excel's
DEC2HEX
and
HEX2DEC
functions... but you can't plug the entire 8 digits into them; you would convert each 2-digit color individually.
... and hit Return...
... it'll return an 8-digit code for you, thus:
This was just a coincidence that it's also 8 digits. This is actually a VBA color code (data type "Long").
They range from
0 (the same as using
vbBlack
) to
16777215 (the same as
vbWhite
).
The
RGB
function in VBA "simply" converts red, green, and blue values (0 to 255) to the "long" vba color code with this formula:
red + ( green * 256 ) + ( blue * 256 * 256 )
On top of those, there are also "
color indexes" which is yet another way to specify colors, specific to Office.
More info: VBA Color Constants,
Hex to RGB,
VBA's RGB function,
Convert color codes and
Working with colors in VBA.