Partilhar via


NamedRange.Text Property

Gets the text for the NamedRange control.

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

Syntax

'Declaration
ReadOnly Property Text As Object
Object Text { get; }

Property Value

Type: System.Object
The text for the NamedRange control.

Remarks

Returns nulla null reference (Nothing in Visual Basic) for NamedRange controls with multiple cells.

Examples

The following code example compares how the Text and Value2 properties differ for cells that contain formatted numbers.

This example is for a document-level customization.

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

        namedRange1.Value2 = 1198.3
        namedRange1.NumberFormat = "$#,##0" 

        ' Displays "1198.3".
        MessageBox.Show("The Value2 value is: " & _
            namedRange1.Value2.ToString())

        ' Displays "$1,198".
        MessageBox.Show("The Text value is: " & _
            namedRange1.Text.ToString())
    End Sub
private void DisplayText()
{
    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1"],
        "namedRange1");
    namedRange1.Value2 = 223;

    namedRange1.Value2 = 1198.3;
    namedRange1.NumberFormat = "$#,##0";

    // Displays "1198.3".
    MessageBox.Show("The Value2 value is: " +
        namedRange1.Value2.ToString());

    // Displays "$1,198".
    MessageBox.Show("The Text value is: " +
        namedRange1.Text.ToString());
}

.NET Framework Security

See Also

Reference

NamedRange Interface

Microsoft.Office.Tools.Excel Namespace