NamedRange.NumberFormat Property (2007 System)

Gets or sets the format code 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 Property NumberFormat As Object
'Usage
Dim instance As NamedRange 
Dim value As Object 

value = instance.NumberFormat

instance.NumberFormat = value
[BrowsableAttribute(false)]
public Object NumberFormat { get; set; }
[BrowsableAttribute(false)]
public:
property Object^ NumberFormat {
    Object^ get ();
    void set (Object^ value);
}
public function get NumberFormat () : Object 
public function set NumberFormat (value : Object)

Property Value

Type: System.Object
The format code for the NamedRange control.

Remarks

This property returns nulla null reference (Nothing in Visual Basic) if all cells in the NamedRange control do not have the same number format.

The format code is the same string as the Format Codes option in the Format Cells dialog box. The Format function uses different format code strings than do the NumberFormat and NumberFormatLocal properties.

Examples

The following code example uses the NumberFormat property to format a date string in a NamedRange. The example also uses the NumberFormatLocal property to display the date format in the language of the user.

This example is for a document-level customization.

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

Private Sub ApplyNumberFormatting()
    formatRange = Me.Controls.AddNamedRange( _
        Me.Range("C1"), "formatRange")

    Me.formatRange.Value2 = "4-Apr-1974" 
    Me.formatRange.NumberFormat = "m/d/yyyy" 

    ' Display the number format in the language of the user.
    MessageBox.Show("The number format for the NamedRange is: " & _
        Me.formatRange.NumberFormatLocal.ToString())
End Sub
Microsoft.Office.Tools.Excel.NamedRange formatRange;
private void ApplyNumberFormatting()
{
    formatRange = this.Controls.AddNamedRange(
         this.Range["C1", missing], "formatRange");

    this.formatRange.Value2 = "4-Apr-1974";
    this.formatRange.NumberFormat = "m/d/yyyy";

    // Display the number format in the language of the user.
    MessageBox.Show("The number format for the NamedRange is: " +
        this.formatRange.NumberFormatLocal.ToString());
}

.NET Framework Security

See Also

Reference

NamedRange Class

NamedRange Members

Microsoft.Office.Tools.Excel Namespace