Excel 2003 - Color codes

  • Thread starter Thread starter thomas
  • Start date Start date
T

thomas

Hello,

I was using the colorindex of the palette in my vba code (2003) but it's not
convenient because it gives different colors when the vba code is used on
excel workbooks with a different palette

I though i would get the same color whatever the palette by using RGB codes
instead but i have the same problem : For example, RGB (204, 255, 204) gives
different colors in different workbooks

How can i get always the same colors?

Thanks
 
The only way would be to configure the colours of every workbook as it was
opened. Excel will map any colour that you define to the closest match on
the standard color palette and use that colorindex.
 
The palette only contains 56 colours, in a default palette there are 10
duplicates. If you attempt to apply your own RGB Excel will match it to the
closest it can find in the palette.

Your particular RGB example does exist in a default palette, so if index 35
has not been customized you will get a perfect match.

If you want to be sure your colour is applied, but only customize a palette
colour if necessary you could do something like this

colVal = RGB(234, 255, 234) ' very pale green
With Range("a1").Interior
.Color = colVal
If .Color <> colVal Then
' the RGB doesn't exist
ActiveWorkbook.Colors(25) = colVal
.ColorIndex = 25
End If
End With


Of course you'd need to be sure you are not messing with someones carefully
customized colour.

Regards,
Peter T
 
Many thanks

I now better understand



"Peter T" <peter_t@discussions> a écrit dans le message de groupe de
discussion : (e-mail address removed)...
The palette only contains 56 colours, in a default palette there are 10
duplicates. If you attempt to apply your own RGB Excel will match it to the
closest it can find in the palette.

Your particular RGB example does exist in a default palette, so if index 35
has not been customized you will get a perfect match.

If you want to be sure your colour is applied, but only customize a palette
colour if necessary you could do something like this

colVal = RGB(234, 255, 234) ' very pale green
With Range("a1").Interior
.Color = colVal
If .Color <> colVal Then
' the RGB doesn't exist
ActiveWorkbook.Colors(25) = colVal
.ColorIndex = 25
End If
End With


Of course you'd need to be sure you are not messing with someones carefully
customized colour.

Regards,
Peter T
 
so it's useless to use RGB codes. better keeping using colorindex ?


"thomas" <nomail> a écrit dans le message de groupe de discussion :
(e-mail address removed)...
Many thanks

I now better understand



"Peter T" <peter_t@discussions> a écrit dans le message de groupe de
discussion : (e-mail address removed)...
The palette only contains 56 colours, in a default palette there are 10
duplicates. If you attempt to apply your own RGB Excel will match it to the
closest it can find in the palette.

Your particular RGB example does exist in a default palette, so if index 35
has not been customized you will get a perfect match.

If you want to be sure your colour is applied, but only customize a palette
colour if necessary you could do something like this

colVal = RGB(234, 255, 234) ' very pale green
With Range("a1").Interior
.Color = colVal
If .Color <> colVal Then
' the RGB doesn't exist
ActiveWorkbook.Colors(25) = colVal
.ColorIndex = 25
End If
End With


Of course you'd need to be sure you are not messing with someones carefully
customized colour.

Regards,
Peter T
 
Not necessarily "useless to use RGB codes" at all, depends on the overall
scenario. Sometimes RGB values are exactly what you do want to use.

Regards,
Peter T
 
They are exactly what i want but if this is the closest color in the palette
that is finally choosen it , not much interest

"Peter T" <peter_t@discussions> a écrit dans le message de groupe de
discussion : [email protected]...
Not necessarily "useless to use RGB codes" at all, depends on the overall
scenario. Sometimes RGB values are exactly what you do want to use.

Regards,
Peter T
 
Back
Top