ActiveX Checkbox Colour

tlc53

Active Member
Joined
Jul 26, 2018
Messages
399
Hi there,

How do I change the background colour on my activeX checkbox?
The RGB colour is 226, 242, 246 but how do I convert that into a code that resembles this: &H80000018&

Thank you!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
On the Developer tab >>Design Mode>>Right click on the check box>>Select Properties>>Change the Back color as required
 
Upvote 0
On the Developer tab >>Design Mode>>Right click on the check box>>Select Properties>>Change the Back color as required
The background colour options are standard colours and I want it to match the colour scheme I have used. I am not sure how I convert my RGB colour to the colour code that activeX uses. Eg. &H80000018&
Do you know what this colour coding is called? If I knew that, perhaps I could find a converter. Thanks
 
Upvote 0
Quick Google search revealed (amongst others) this...

Another approach might be, not to try & convert the colour, but as you want to match it to your extant scheme, just make it equal to something else already in your scheme:
VBA Code:
Sub chng_col()
With ActiveSheet
   .CheckBox1.BackColor = .CommandButton1.BackColor
End With
End Sub
 
Upvote 0
... you could also use your "immediate window" to run code..
If you type your RGB into the window, preceded by a question mark
VBA Code:
?rgb(226, 242, 246)
... and hit Return...
... it'll return an 8-digit code for you, thus:
VBA Code:
 16184034
If you then paste that into the (for example) BackColor property box of your CheckBox, as soon as you exit the field, it'll change the control's colour, and put the full Windows hexadecimal code in it's place - in the same field:
Capture2.JPG
 
Upvote 0
Solution
If you then paste that into the (for example) BackColor property box of your CheckBox, as soon as you exit the field, it'll change the control's colour, and put the full Windows hexadecimal code in it's place - in the same field:
Perfect! That's exactly what I was hoping to achieve.
Thanks very much! :)
 
Upvote 0
...I am not sure how I convert my RGB colour to the colour code that activeX uses. Eg.
VBA Code:
&H80000018&
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.

VBA Code:
?rgb(226, 242, 246)
... and hit Return...
... it'll return an 8-digit code for you, thus:
VBA Code:
16184034
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.
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,245
Members
448,555
Latest member
RobertJones1986

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top