Partager via


NamedRange.FormatConditions Property

Gets a FormatConditions collection that represents all the conditional formats for the NamedRange control.

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

Syntax

'Declaration
ReadOnly Property FormatConditions As FormatConditions
FormatConditions FormatConditions { get; }

Property Value

Type: Microsoft.Office.Interop.Excel.FormatConditions
A FormatConditions collection that represents all the conditional formats for the NamedRange control.

Examples

The following code example creates a NamedRange and then uses the FormatConditions property to alter the font in the NamedRange if the value in the NamedRange is less than the value of cell A1.

This example is for a document-level customization.

Private formatConditionsRange As Microsoft.Office.Tools.Excel.NamedRange

Private Sub ModifyFormatConditions()
    formatConditionsRange = Me.Controls.AddNamedRange( _
        Me.Range("B1"), "formatConditionsRange")
    Me.Range("A1").Value2 = 99000
    Me.formatConditionsRange.Value2 = 98052

    ' Set conditional formatting to alter the font if  
    ' the formatConditionsRange value is less than the value in A1. 
    Dim condition1 As Excel.FormatCondition = _
        Me.formatConditionsRange.FormatConditions.Add( _
        Excel.XlFormatConditionType.xlCellValue, _
        Excel.XlFormatConditionOperator.xlLess, "=$a$1", )

    condition1.Font.Bold = True
    condition1.Font.Color = &HFF00
End Sub
Microsoft.Office.Tools.Excel.NamedRange formatConditionsRange;
private void ModifyFormatConditions()
{
    formatConditionsRange = this.Controls.AddNamedRange(
        this.Range["B1"], "formatConditionsRange");
    this.Range["A1"].Value2 = 99000;
    this.formatConditionsRange.Value2 = 98052;

    // Set conditional formatting to alter the font if  
    // the formatConditionsRange value is less than the value in A1.
    Excel.FormatCondition condition1 =
        (Excel.FormatCondition)this.formatConditionsRange.FormatConditions.Add(
        Excel.XlFormatConditionType.xlCellValue,
        Excel.XlFormatConditionOperator.xlLess, "=$a$1");

    condition1.Font.Bold = true;
    condition1.Font.Color = 0xFF00;
}

.NET Framework Security

See Also

Reference

NamedRange Interface

Microsoft.Office.Tools.Excel Namespace