Blue Accent 5 Lighter 60 Color Code
VBA has several ways of defining a color as listed below.
VB Color Constants
This is the most simple system. VBA includes a few basic colors as constants.
vbBlack, vbBlue, vbCyan, vbGreen, vbMagenta, vbRed, vbWhite, vbYellow
Range("A1").Interior.Color = vbRed
( n.b. These are actually translated to the RGB Color System values discussed below)
VB Color Index
VBA includes 56 colors that are numbered in a system called ColorIndex. (n.b. you must use the property ColorIndex, not .Color)
Range("A1").Interior.ColorIndex = 30
VBA Theme Colors
Theme colors are a set of 60 colors and tints that work well together as determined by the theme designer. By using only choices from this palette the sheet should be pleasing to the human eye. Rather than the 60 colors being defined as specific colors they are identified with theme color names such as "Accent 25%" or "Dark 50%." Each theme then assigns a specific color to each of the theme color names. When the theme of the sheet is changed all of the theme colors take on their new specific colors.
By hand, the theme colors are selected from a matrix viewed in Menu: Home/Font/FillColor or FontColor.
Columns (10) represent white, black and 8 more theme colors named with standard descriptions
Rows (6) represent tints (degree of darkness) within a theme color named as percents
By VBA code, to use a theme color two properties must be set: both .ThemeColor and .TintShade
The ThemeColors (10 columns) are named:
.ThemeColor = xlThemeColorDark1 (whites)
.ThemeColor = xlThemeColorLight1 (blacks)
.ThemeColor = xlThemeColorDark2
.ThemeColor = xlThemeColorLight2
.ThemeColor = xlThemeColorAccent1
.ThemeColor = xlThemeColorAccent2
.ThemeColor = xlThemeColorAccent3
.ThemeColor = xlThemeColorAccent4
.ThemeColor = xlThemeColorAccent5
.ThemeColor = xlThemeColorAccent6
The TintShade (6 rows) use a value from -1 to +1 (data type single)
-1 (darkest) to +1 (lightest)
Zero (0) is neutral.
Other values are best determined from a quick demonstration macro.
n.b. in code do not use the % values that you see in the menu
(# ## in process###) For the Office theme (default) the values are shown in the in table below
VB RGB Color System
The RGB system is the usual way to identify a color in VB. The RGB Color System uses a value to identify one color on a color map that is made up of all combinations of 256 red values, 256 green values and 256 blue values (total number of colors = 256^3 = 16,777,216). RGB Color System is an additive system starting with black – low values are very dark and high values very close to white.
Be careful of tricky terminology:
RGB Color System A way to identify one color out of all possible combinations of 256 values each for red, green and blue
RGB Color System MapA palette of all the colors available in the RGB Color System
RGB Color System Value An integer from 0 to 16,777,216 that identifies a given color.
RGB() function An Excel VBA function that converts three values (red, green and blue) into the RGB Color System value.
There are three ways to provide the RGB Color System Value that is needed to set a .Color property
1 - RGB Color System Value as an integer (data type long between 0 and 16,777,216). You can get the value by recording a demo macro that uses Fill Color / More Colors / custom.
Selection.Interior.Color = 5 916220
2 - Use the function RGB(red,green,blue) to convert from decimal values for each color into the RGB Color System value.
RGB(60,70,90) will return 5916220 (you can check it in immediate window as ? RGB(60,70,90) )
Selection.Interior.Color = RGB(60,70,90) ' sets to RGB Color System value 5916220
3 - Use the function RGB(red,green,blue) to convert from hexidecimal values for each color into the RGB Color System valu e. This is also called "triHex" notation.
Hexidecimal values in Excel VBA must be written with a &H before them.
Selection.Interior.Color = RGB(&H3C, &H46, &H5A) ' will return 5916220 (again, check in immediate window )
Sample of RGB Color System Values
Sample (to come) | Common Name | RGB Color System Value | RGB(red,green,blue) function arguments in hex | RGB(red,green,blue) function arguments in decimal |
................ | Red | 255 | &HFF,&H00,&H00 | 255,0,0 |
............... | Yellow | 65535 | &HFF,&HFF,&H00 | 255,255,0 |
.............. | Green | 32768 | &H00,&H80,&H00 | 0,128,0 |
............... | Blue | 16711680 | &H00,&H00,&HFF | 0,0,255 |
.......... | Purple | 8388736 | &H80,&H00,&H80 | 128,0,128 |
.............. | Black | 0 | &H00,&H00,&H00 | 0,0,0 |
.......... | White | 16777215 | &HFF,&HFF,&HFF | 255,255,255 |
.......... | Gray | 8421504 | &H80,&H80,&H80 | 128,128,128 |
.......... | Violet | 16745198 | &HEE,&H82,&HEE | 238,130,255 |
.......... | Orange | 42495 | &HFF,&HA5,&H00 | 255,165,0 |
.......... | Dark Blue | 9109504 | &H00,&H00,&H8B | 0,0,139 |
.......... | Light Blue | 15128749 | &HAD,&HD8,&HE6 | 173,216,230 |
.......... | Cornsilk | 14481663 | &HFF,&HF8,&HDC | 255,248,220 |
.......... | Goldenrod | 2139610 | &HDA,&HA5,&H20 | 218,165,32 |
.......... | Peru | 4163021 | &HCD,&H85,&H3F | 205,133,63 |
Conversion Techniques
Known | Desired | Technique |
Visual ID of a color on the RGB Color System Map | Values for arguments in RGB() function in decimal | Excel Menu: Home/Fill Color/More Colors/Custom |
Values in RGB() function | Visual appearance of the color | http://www.zebra0.com/color/index.php |
Values for arguments in RGB() function as decimal | RGB Color System Value | (red)+(green*256)+(blue*256*256) Or, logically: (red*256^0) + (green*256^1) + (blue*256^2) |
RGB Color System Value | Values for arguments in RGB() function as decimals | 'Col=RGB Color System Value R = Col Mod 256 G = (Col \ 256) Mod 256 B = (Col \ 256 \ 256) Mod 256 |
Values for arguments in RGB() function as hex | RGB Color System Value | ### to come |
RGB Color System Value | Values for arguments in RGB() function as hex | ### to come |
RGB Color System Value between dec and hex | RGB Color System Value between dec and hex | Windows Calculator / View / Programmer... |
??? To answer in future
Can VB use HTML color set (original & X11) ?
example in Java Script: rgMyReferencedRange.setBackgroundColor("red");
What is the system of Fill Color / More Colors / Custom / HSL?
Add to table of sample values the actual colors as a fill in a cell
SchemeColors system - linked to Windows Scheme?
Is Selection.Interior.RGB = RGB(128, 0, 0) supported? Mentioned in help but not working
. Shapes ( xName ). Fill . ForeColor . RGB = 682978 ( some variable )
Color Exercises (in process)
Set the background color of a cell(s) as follows.
- Largest, smallest and median values for arguments for Hex and RGB notation
- Do a series of ten cells where one argument of RGB() changes by 10% per cell (use loop)
- Try making a spreadsheet that has all the combinations of Red and Green values in 50 step increments. Blue will always stay at 0.
Blue Accent 5 Lighter 60 Color Code
Source: https://www.sites.google.com/site/20121031excelvbaaae/vb-color-systems