Colors Property

Microsoft Office Web Components Visual Basic

expression.Colors(Index)

expression    Required. An expression that returns a Workbook object.

Index   Optional Variant. The color number (from 1 to 56). If this argument isn’t specified, this method returns an array that contains all 56 of the colors in the palette.

Example

This example sets color five in the color palette for the active workbook.

Spreadsheet1.ActiveWorkbook.Colors(5) = RGB(255, 0, 0)
		

This example creates a table on the active worksheet in Spreadsheet1 that displays the available color palette.

Sub Create_Color_Table()
    Dim avarColorArray()
    Dim iCtr
    Dim rngCurrent

    ' Set an array variable to the colors in the color palette.
    avarColorArray = Spreadsheet1.ActiveWorkbook.Colors

    Set rngCurrent = Spreadsheet1.ActiveSheet.Range("A1")

    ' Loop through all of the colors in the array.
    For iCtr = 1 To UBound(avarColorArray)
        rngCurrent.Value = "Color " & iCtr

        ' Set the color of a cell in column B to
        ' the appropriate color.
        rngCurrent.Offset(0, 1).Interior.Color _
                        = avarColorArray(iCtr)

        Set rngCurrent = rngCurrent.Offset(1, 0)
    Next
End Sub