color setting from the grid to RGB() in VBA (1 Viewer)

neuroman9999

Member
Local time
Today, 07:11
Joined
Aug 17, 2020
Messages
836
does anyone have any simple conversions for this? I have this code:
Code:
        ws.Cells(row, col).Interior.Color = RGB(0, 0, 205)
however, what someone is asking me is to produce this color:
Code:
         ws.Cells(row, col).Interior.ThemeColor = xlThemeColorLight2
and of course I do not know the RGB equivalent of that enum, nor can I find anything on the web, anywhere, that gives tables for this. You would think it would be out there somewhere. This is the closest I've found: http://www.wordarticles.com/Articles/Colours/2007.php

However, that article is way too complex, and not even close to spending the time on. Writing custom enums and/or classes for something this small is not practical. I can always accomplish the goal by writing this:
Code:
        ws.Cells(row, col).Interior.Pattern = xlSolid
        ws.Cells(row, col).Interior.PatternColorIndex = xlAutomatic
        ws.Cells(row, col).Interior.ThemeColor = xlThemeColorLight2
        ws.Cells(row, col).Interior.TintAndShade = -0.249977111117893
        ws.Cells(row, col).Interior.PatternTintAndShade = 0
however, that's way too much code. It doesn't matter though, because the speed of the code doesn't take a hit regardless of the way I write it. Anyone know the shortened version?
 

The_Doc_Man

Immoderate Moderator, Former MVP, Retired SysAdmin
Staff member
Local time
Today, 07:11
Joined
Feb 28, 2001
Messages
18,324
That "xlThemeColorLight2" is a reference to the current Excel theme, which you can select from the ribbon.


That value will probably be some constant used as an index to an internal table that might be hard to find. Unfortunately, there will be no easy way to reach into Excel to determine the color because (if I read it correctly), it is a doubly-indexed table. First index is a theme number and the list of themes numbers to at least 150. Second index is a color within the theme. I don't know of a simple way to shorten that code, but only one of those actions actually sets the color. The other lines set other attributes that would be changeable independently of color.
 

neuroman9999

Member
Local time
Today, 07:11
Joined
Aug 17, 2020
Messages
836
I don't know of a simple way to shorten that code, but only one of those actions actually sets the color. The other lines set other attributes that would be changeable independently of color.
actually I don't think that's right Richard. because I've run 10 tests already, running the code through with each line, one by one (singly present) and none of them that I remember just colored the BG of the cell. there was always something else that happened to it. it was shaded a bit, etc...

the person I'm doing this for is pretty strange, but it doesn't matter. his requests are complied with, no matter how strange they are.
 

Users who are viewing this thread

Top Bottom