Colour code in VBA

R

Robin Chapple

I have a routine that includes this line to add a grey background.

Const adhcColourGrey = &HC0C0C0

I would prefer a paler shade of grey like this: 15132390 which is the
"Back Color" value.

How do I covert it to the VBA type code?

Thanks,

Robin Chapple
 
R

Randy Harris

Robin Chapple said:
I have a routine that includes this line to add a grey background.

Const adhcColourGrey = &HC0C0C0

I would prefer a paler shade of grey like this: 15132390 which is the
"Back Color" value.

How do I covert it to the VBA type code?

Thanks,

Robin Chapple

Const adhcColourGrey = 15132390
 
R

Robin Chapple

Thanks Randy,

That worked a treat.

For the sake of knowledge why do some need the ampersand?

Cheers,

Robin
 
J

John Vinson

Thanks Randy,

That worked a treat.

For the sake of knowledge why do some need the ampersand?

&H is a prefix which tells VBA to interpret the number as hexadecimal.
That is, &H10 = 16; &HFF = 255.

A color number is three packed 2-byte binary numbers, for red, green,
and blue respectively. &HC0C0C0 is 192 = &HC0 units of red (out of 255
possible), 255 of green, and 255 of blue; if you want a paler grey you
could use &HE0E0E0, or for darker, use &HA0A0A0.

This number can also be expressed as a decimal long integer; &HC0C0C0
is 12632256. Setting the ForeColor property of an object can be done
using either expression, they're just two ways of writing the same
number.

John W. Vinson[MVP]
 
R

Robin Chapple

Thanks John,

I will archive the explanation because I do not use this application
of Colour to VBA very often.

Regards,

Robin Chapple
 

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