Megosztás a következőn keresztül:


NamedRange.Address Property

Gets the range reference for the NamedRange control.

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

Syntax

'Declaration
ReadOnly Property Address As NamedRange_AddressType
NamedRange_AddressType Address { get; }

Property Value

Type: Microsoft.Office.Tools.Excel.NamedRange_AddressType
A string that represents the range reference of the NamedRange control in R1C1-stye or A1-style notation.

Remarks

The Address property is intended to be used with the following parameters.

Parameter

Description

RowAbsolute

true to return the row as an absolute reference. The default value is true.

ColumnAbsolute

true to return the column as an absolute reference. The default value is true.

ColumnAbsolute

One of the XlReferenceStyle values.

External

true to return an external reference; false to return a local reference. The default value is false.

RelativeTo

A Range that defines the starting point. If RowAbsolute and ColumnAbsolute are false, and ReferenceStyle is xlR1C1, you must include a starting point for the relative reference.

If you attempt to use Address without specifying any parameters, Address will get a NamedRange_AddressType object that is part of the Visual Studio infrastructure and is not intended to be used directly from your code.

If the reference contains more than one cell, RowAbsolute and ColumnAbsolute apply to all rows and columns.

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

Examples

The following code example creates a NamedRange and then displays the address of the NamedRange in four formats.

This version is for a document-level customization.

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

        ' The following code will display "$A$2:$C$4".
        MessageBox.Show(namedRange1.Address(True, True, _
            Excel.XlReferenceStyle.xlA1, False, ))

        ' The following code will display "$A2:$C4".
        MessageBox.Show(namedRange1.Address(False, True, _
            Excel.XlReferenceStyle.xlA1, False, ))

        ' The following code will display "R2C1:R4C3".
        MessageBox.Show(namedRange1.Address(True, True, _
            Excel.XlReferenceStyle.xlR1C1, False, ))

        ' The following code will display "R[-1]C[-2]:R[1]C".
        MessageBox.Show(namedRange1.Address(False, False, _
            Excel.XlReferenceStyle.xlR1C1, False, Me.Cells(3, 3)))
    End Sub
private void DisplayAddress()
{
    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A2","C4"],
        "namedRange1");

    // The following code will display "$A$2:$C$4".
    MessageBox.Show(namedRange1.Address[true, true,
        Excel.XlReferenceStyle.xlA1, false]);

    // The following code will display "$A2:$C4".
    MessageBox.Show(namedRange1.Address[false, true,
        Excel.XlReferenceStyle.xlA1, false]);

    // The following code will display "R2C1:R4C3".
    MessageBox.Show(namedRange1.Address[true, true,
        Excel.XlReferenceStyle.xlR1C1, false]);

    // The following code will display "R[-1]C[-2]:R[1]C".
    MessageBox.Show(namedRange1.Address[false, false,
        Excel.XlReferenceStyle.xlR1C1, false, this.Cells[3, 3]]);
}

This version is for an application-level add-in.

.NET Framework Security

See Also

Reference

NamedRange Interface

Microsoft.Office.Tools.Excel Namespace