View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
keepITcool keepITcool is offline
external usenet poster
 
Posts: 2,253
Default Are there apis that relate colour index with color?

Jan..

The colors are stored in the workbook's Colors property
it's an array of long color values. Colorindex is 1 to 56.


ActiveWorkbook.ResetColors resets the workbooks colors array to the
defaults.


Be careful converting the long to hex as this produces BGR not RGB!!

Demo: type following in the immediate pane... :)

msgbox hex(rgb(255,254,253))


You'll get the color as follows:

Option Explicit
Sub GetColors()
Dim i&, lngColor&, strRGB$
For i = 1 To 56
'get the long
lngColor = ActiveWorkbook.Colors(i)
'convert long to rgb hex
strRGB = Lng2Rgb(lngColor)
Cells(i, 1) = i
Cells(i, 2) = lngColor
Cells(i, 3) = "'" & strRGB
Cells(i, 1).Resize(, 3).Interior.Color = lngColor
Next
End Sub

Function Lng2Rgb$(lng&)
Dim r, g, b
r = (lng Mod (2 ^ 8)) \ 2 ^ 0
g = (lng Mod (2 ^ 16)) \ 2 ^ 8
b = (lng Mod (2 ^ 24)) \ 2 ^ 16
Lng2Rgb = Format(Hex(r), "00") & _
Format(Hex(g), "00") & _
Format(Hex(b), "00")
End Function


suc6!

keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Jan Nordgreen" wrote:

Thanks.

When I searched for the answer to my question, I looked at his
colourful page, but did not find any api functions.

He gets the color values by reading cells he has set the color index
of.

( Cells(i + 1, 2).Font.colorindex = i
Cells(i + 1, 2).Value = "[Color " & i & "]"
str0 = Right("000000" & Hex(Cells(i + 1, 1).Interior.color), 6))

I was wondering if there is a direct link.

Sincerely,

Jan Nordgreen

"Tom Ogilvy" wrote in message
...
Maybe there is some information here at David McRitchie's site:

http://www.mvps.org/dmcritchie/excel/colors.htm

--
Regards,
Tom Ogilvy

Jan Nordgreen wrote in message
...
The relationship between the forty colour index number you get from
the default colour palette when you press Fill Color and the
background

colour
values is given below if you swap the last two digist with the two

first.

My query is: do apis exist that calculates the one given the other?

Sincerely,

Jan Nordgreen
Santa Cruz, Bolivia

aPalColour(1) = "000000"
aPalColour(2) = "FFFFFF"
aPalColour(3) = "FF0000"
aPalColour(4) = "00FF00"
aPalColour(5) = "0000FF"
aPalColour(6) = "FFFF00"
aPalColour(7) = "FF00FF"
aPalColour(8) = "00FFFF"
aPalColour(9) = "800000"
aPalColour(10) = "008000"
aPalColour(11) = "000080"
aPalColour(12) = "808000"
aPalColour(13) = "800080"
aPalColour(14) = "008080"
aPalColour(15) = "C0C0C0"
aPalColour(16) = "808080"
aPalColour(33) = "00CCFF"
aPalColour(34) = "CCFFFF"
aPalColour(35) = "CCFFCC"
aPalColour(36) = "FFFF99"
aPalColour(37) = "99CCFF"
aPalColour(38) = "FF99CC"
aPalColour(39) = "CC99FF"
aPalColour(40) = "FFCC99"
aPalColour(41) = "3366FF"
aPalColour(42) = "33CCCC"
aPalColour(43) = "99CC00"
aPalColour(44) = "FFCC00"
aPalColour(45) = "FF9900"
aPalColour(46) = "FF6600"
aPalColour(47) = "666699"
aPalColour(48) = "969696"
aPalColour(49) = "003366"
aPalColour(50) = "339966"
aPalColour(51) = "003300"
aPalColour(52) = "333300"
aPalColour(53) = "993300"
aPalColour(54) = "993366"
aPalColour(55) = "333399"
aPalColour(56) = "333333"