NamedRange.Validation Property (2007 System)

Gets a Validation object that represents data validation for the NamedRange control.

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 ReadOnly Property Validation As Validation
'Usage
Dim instance As NamedRange 
Dim value As Validation 

value = instance.Validation
[BrowsableAttribute(false)]
public Validation Validation { get; }
[BrowsableAttribute(false)]
public:
property Validation^ Validation {
    Validation^ get ();
}
public function get Validation () : Validation

Property Value

Type: Validation
A Validation object that represents data validation for the NamedRange control.

Remarks

You must use the Startup event handler of a worksheet to add validation to a named range. For more information about the Startup event handler, see Visual Studio Tools for Office Project Events.

Examples

The following code example uses the Validation property to verify that a string with at least three characters is entered into a NamedRange. The SetValidation method must be called from the Startup event handler.

This example is for a document-level customization.

Private Sub SetValidation()
    Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
        = Me.Controls.AddNamedRange(Me.Range("A1"), _
        "namedRange1")

    namedRange1.Validation.Add( _
        Excel.XlDVType.xlValidateTextLength, _
        Excel.XlDVAlertStyle.xlValidAlertStop, _
        Excel.XlFormatConditionOperator.xlGreater, 3, )

    namedRange1.Validation.InputMessage = "Enter a name."
    namedRange1.Validation.ErrorMessage = _
        "Please enter a name with 3 or more characters." 
End Sub
private void SetValidation()
{
    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", missing],
        "namedRange1");

    namedRange1.Validation.Add(
        Excel.XlDVType.xlValidateTextLength,
        Excel.XlDVAlertStyle.xlValidAlertStop,
        Excel.XlFormatConditionOperator.xlGreater, 3, missing);

    namedRange1.Validation.InputMessage = "Enter a name.";
    namedRange1.Validation.ErrorMessage =
        "Please enter a name with 3 or more characters.";
}

.NET Framework Security

See Also

Reference

NamedRange Class

NamedRange Members

Microsoft.Office.Tools.Excel Namespace