Udostępnij za pośrednictwem


Workbook.Colors Property (2007 System)

Gets or sets colors in the palette for the workbook.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)

Syntax

'Declaration
<BrowsableAttribute(False)> _
Public Overridable ReadOnly Property Colors As Workbook._ColorsType
'Usage
Dim instance As Workbook 
Dim value As Workbook._ColorsType 

value = instance.Colors
[BrowsableAttribute(false)]
public virtual Workbook._ColorsType Colors { get; }
[BrowsableAttribute(false)]
public:
virtual property Workbook._ColorsType^ Colors {
    Workbook._ColorsType^ get ();
}
public function get Colors () : Workbook._ColorsType

Property Value

Type: Microsoft.Office.Tools.Excel.Workbook._ColorsType
An RGB color value in the color palette for the workbook, or an array that contains all 56 RGB color values in the color palette for the workbook.

Remarks

The Colors property can be used with the following parameter.

Parameter

Description

Index

The index number of a color in the workbook color palette (from 1 to 56). If this argument is not specified, this property returns an array that contains all 56 of the colors in the palette.

If you attempt to use Colors without specifying any parameters, Colors will get a Workbook._ColorsType object that is part of the Visual Studio Tools for Office infrastructure and is not intended to be used directly from your code.

The workbook palette has 56 entries, each represented by an RGB value.

Optional Parameters

For information on optional parameters, see The Variable missing and Optional Parameters in Office Solutions.

Examples

The following code example uses the Colors property to set the first color in the workbook's color palette to blue, and then programmatically displays the Microsoft Office Excel Color Palette dialog to verify that this change was made.

This version is for a document-level customization.

Private Sub SetFirstColorInPalette()
    Me.Colors(1) = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Blue)
    Me.Application.Dialogs( _
        Excel.XlBuiltInDialog.xlDialogColorPalette).Show()
End Sub
private void SetFirstColorInPalette()
{
    this.Colors[1] = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Blue);

    this.Application.Dialogs[
        Excel.XlBuiltInDialog.xlDialogColorPalette].Show(
        missing, missing, missing, missing, missing, missing,
        missing, missing, missing, missing, missing, missing,
        missing, missing, missing, missing, missing, missing,
        missing, missing, missing, missing, missing, missing,
        missing, missing, missing, missing, missing, missing);
}

This version is for an application-level add-in.

Private Sub SetFirstColorInPalette()
    Dim vstoWorkbook As Workbook = Me.Application.ActiveWorkbook.GetVstoObject()
    vstoWorkbook.Colors(1) = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Blue)
    vstoWorkbook.Application.Dialogs( _
        Excel.XlBuiltInDialog.xlDialogColorPalette).Show()
End Sub
private void SetFirstColorInPalette()
{
    Workbook vstoWorkbook = this.Application.ActiveWorkbook.GetVstoObject();
    vstoWorkbook.Colors[1] = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Blue);

    vstoWorkbook.Application.Dialogs[
        Excel.XlBuiltInDialog.xlDialogColorPalette].Show(
        missing, missing, missing, missing, missing, missing,
        missing, missing, missing, missing, missing, missing,
        missing, missing, missing, missing, missing, missing,
        missing, missing, missing, missing, missing, missing,
        missing, missing, missing, missing, missing, missing);
}

.NET Framework Security

See Also

Reference

Workbook Class

Workbook Members

Microsoft.Office.Tools.Excel Namespace

Change History

Date

History

Reason

July 2008

Added a version of the code example for an application-level add-in.

SP1 feature change.