Unbelievable! Hex colors don’t work in VBA without conversion!
It is totally unbelievable to me but today I wanted to put an ActiveX option button on an Excel worksheet. I could set the BackStyle to transparent so I can see the color in the worksheet through it but every time I clicked the option button it showed up white – and UGLY.
I managed to get the hex color of the worksheet – I got the RGB from Excel then put it in PaintShop Pro to get the hex value. So R242, G157, B 0 became #F29D00 hex.
At this point I was feeling rightly proud of my color conversion skills until I tried to set the Backcolor property to this value. It WAS BLUE!? not orange… WTF?
Seems like VBA color isn’t the same as Hex colors … it is nearly the same but not quite. You need to switch the R and B values with each other. So my orange #F29D00 becomes #009DF2 for VBA – of course you need to then wrap it in the other little bits so it looks like this: &H009DF2& and all is hunky dory. Paste that into the Properties box and VBA makes it into a nice long integer all by itself – that bit at least is simple.
So now you know how to convert hex colors to VBA colors.
I just have to ask the burning question – WHY? Why isn’t good ol’ RGB good enough for Microsoft – why is it BGR? And just which programming genius dreamed that one up?