This documentation is archived and is not being maintained.

How to: Apply Color to Excel Ranges

NoteNote

Some code examples in this topic use the this or Me keyword or the Globals class in a way that is specific to document-level customizations, or they rely on features of document-level customizations such as host controls. These examples can be compiled only if you have the required applications installed. For more information, see Features Available by Product Combination.

You can set the Color property of a range to apply a color to text within a range of cells in Microsoft Office Excel 2003.

The range can be one of two types:

Using Host Controls

To apply color to a NamedRange control

  1. Create a NamedRange control at cell A1.

    Microsoft.Office.Tools.Excel.NamedRange rng =
        this.Controls.AddNamedRange(this.Range["A1", missing], "NamedRange1");
    
    
  2. Set the color of the text in the NamedRange control.

    rng.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
    
    

Using Excel Objects

To apply color to a Range object

  • Set the color of the text in the specified range.

    Excel.Range rng2 = this.Application.get_Range("A1", missing);
    rng2.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
    
    

See Also

Show: