NamedRange.Address 屬性

取得 NamedRange 控制項的範圍參照。

命名空間:  Microsoft.Office.Tools.Excel
組件:  Microsoft.Office.Tools.Excel (在 Microsoft.Office.Tools.Excel.dll 中)

語法

'宣告
ReadOnly Property Address As NamedRange_AddressType
NamedRange_AddressType Address { get; }

屬性值

型別:Microsoft.Office.Tools.Excel.NamedRange_AddressType
字串,表示採用 R1C1 樣式或 A1 樣式標記的 NamedRange 控制項範圍參照。

備註

Address 屬性的用意是要與下列參數一起使用。

參數

描述

RowAbsolute

true 表示以絕對參照的形式傳回列。 預設值是 true。

ColumnAbsolute

true 表示以絕對參照的形式傳回欄。 預設值是 true。

ColumnAbsolute

其中一個 XlReferenceStyle 值。

External

true 代表傳回外部參照,false 代表傳回本機參照。 預設值是 false。

RelativeTo

定義起點的 Range。 如果 RowAbsolute 和 ColumnAbsolute 為 false,且 ReferenceStyle 為 xlR1C1,則必須加入起點做為相對參考位址。

如果您嘗試在不指定任何參數的情況下使用 Address,則 Address 會得到 NamedRange_AddressType 物件,但該物件是 Visual Studio 基礎結構的一部分,並不適合直接在程式碼中使用。

如果參照包含一個以上的儲存格,則 RowAbsolute 和 ColumnAbsolute 會套用至所有的列和欄。

選擇性參數

如需選擇性參數的詳細資訊,請參閱Office 方案中的選擇性參數

範例

下列程式碼範例會建立 NamedRange,然後以四種格式顯示 NamedRange 的位址。

這是示範文件層級自訂的版本。

    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]]);
}

這是示範應用程式層級增益集的版本。

.NET Framework 安全性

請參閱

參考

NamedRange 介面

Microsoft.Office.Tools.Excel 命名空間