XL2000: RGB Function May Map to Unexpected Color (213201)
The information in this article applies to:
This article was previously published under Q213201 SYMPTOMS
When you use the RGBfunction in a Visual Basic for Applications macro, the color value of the RGB color of the index may be mapped to a color other than the color you expected.
For example, RGB(65,0,0) is mapped to Dark Red, but RGB(64,0,0) is mapped
to Black.
CAUSE
This behavior occurs because the color property accepts an RGB triple and maps it to the nearest color index. When the property retrieves the color value, it returns the RGB color of the index, which may be different from the value you typed. In the example, RGB(65,0,0) is mapped to Dark Red (RGB(128,0,0)), but RGB(64,0,0) is mapped to Black (RGB(0,0,0)).
WORKAROUND
To work around this problem, use the ShapeRange
objects collection. The ShapeRange objects collection allows greater flexibility when you change colors in code. Instead of using this
Selection.Interior.Color = RGB(x,y,z)
you can use the following:
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(x,y,z)
REFERENCESFor more information about the ShapeRange collection object, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type ShapeRange Collection Object in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
Modification Type: | Minor | Last Reviewed: | 10/11/2006 |
---|
Keywords: | kbdtacode kbprb kbProgramming KB213201 |
---|
|