RGB Function

Returns a Long representing an RGB color value.

Syntax

RGB( red, green, blue )

The RGB function syntax has these arguments:

Argument

Description

red

Required. Variant (Integer). Number in the range 0–255, inclusive, that represents the red component of the color.

green

Required. Variant (Integer). Number in the range 0–255, inclusive, that represents the green component of the color.

blue

Required. Variant (Integer). Number in the range 0–255, 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


The RGB color values returned by this function are incompatible with those used by the Macintosh operating system. They may be used within the context of Microsoft applications for the Macintosh, but should not be used when communicating color changes directly to the Macintosh operating system.

Example

Note: Examples that follow demonstrate the use of this function in a Visual Basic for Applications (VBA) module. For more information about working with VBA, select Developer Reference in the drop-down list next to Search and enter one or more terms in the search box.

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
' Return the value for Red.
Red = RGB(255, 0, 0)
' Initialize offset.
I = 75
RGBValue = RGB(I, 64 + I, 128 + I)
' Same as RGB(75, 139, 203).
' Set the Color property of MyObject to Red.
MyObject.Color = RGB(255, 0, 0)
Share Facebook Facebook Twitter Twitter Email Email

Was this information helpful?

Great! Any other feedback?

How can we improve it?

Thank you for your feedback!

×