Excel Color Shading
MS Function definition for RGB
from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbenlr98/html/vafctrgb.asp
MSDN Home > MSDN Library > Reference >
Visual Basic for Applications Reference
RGB Function
See Also Example Specifics
Returns a Long whole number representing an RGB color value.
Syntax
RGB(red, green, blue)
The RGB function syntax has these named arguments:
Part Description
red Required; Variant (Integer). Number in the range 0255, inclusive, that represents the red component of the color.
green Required; Variant (Integer). Number in the range 0255, inclusive, that represents the green component of the color.
blue Required; Variant (Integer). Number in the range 0255, inclusive, that represents the blue component of the color.
Remarks
Application methods and properties that accept a color specification expect that specification to be a number representing an RGB color value. An RGB color value specifies the relative intensity of red, green, and blue to cause a specific color to be displayed.
The value for any argument to RGB that exceeds 255 is assumed to be 255.
The following table lists some standard colors and the red, green, and blue values they include:
Color Red Value Green Value Blue Value
Black 0 0 0
Blue 0 0 255
Green 0 255 0
Cyan 0 255 255
Red 255 0 0
Magenta 255 0 255
Yellow 255 255 0
White 255 255 255
From Microsoft Visual Basic... RGB Function example.
RGB Function Example
This example shows how the RGB function is used to return a whole number representing an RGB color value. It is used for those application methods and properties that accept a color specification. The object MyObject and its property are used for illustration purposes only. If MyObject does not exist, or if it does not have a Color property, an error occurs.
Dim RED, I, RGBValue, MyObject
Red = RGB(255, 0, 0) ' Return the value for Red.
I = 75 ' Initialize offset.
RGBValue = RGB(I, 64 + I, 128 + I) ' Same as RGB(75, 139, 203).
MyObject.Color = RGB(255, 0, 0) ' Set the Color property of
' MyObject to Red.
ForeColor sample code from VBA
Private Sub btnStar_Click()
Dim degree#
Dim s As Shape
Const Pi = 3.1415927
Randomize
For degree = 0 To 2 * Pi Step Pi / 12
Set s = ActiveSheet.Shapes.AddLine(200, 200, _
200 + 100 * Sin(degree), 200 + 100 * Cos(degree))
s.Line.EndArrowheadStyle = msoArrowheadTriangle
s.Line.EndArrowheadLength = msoArrowheadLengthMedium
s.Line.EndArrowheadWidth = msoArrowheadWidthMedium
s.Line.ForeColor.RGB = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
Next
End Sub
Notes about how to use indexed color in Excel macros.
ARCHIVES
07/01/2003 - 08/01/2003 /