NamedRange.Address Property (2007 System)
Gets the range reference 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 Address As NamedRange._AddressType
'Usage
Dim instance As NamedRange
Dim value As NamedRange._AddressType
value = instance.Address
[BrowsableAttribute(false)]
public NamedRange._AddressType Address { get; }
[BrowsableAttribute(false)]
public:
property NamedRange._AddressType^ Address {
NamedRange._AddressType^ get ();
}
public function get Address () : NamedRange._AddressType
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 Tools for Office 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 The Variable missing and 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, missing]);
// The following code will display "$A2:$C4".
MessageBox.Show(namedRange1.Address[false, true,
Excel.XlReferenceStyle.xlA1, false, missing]);
// The following code will display "R2C1:R4C3".
MessageBox.Show(namedRange1.Address[true, true,
Excel.XlReferenceStyle.xlR1C1, false, missing]);
// 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.
Private Sub DisplayAddress()
Dim vstoWorksheet As Worksheet = CType( _
Me.Application.ActiveWorkbook.Worksheets(1), _
Excel.Worksheet).GetVstoObject()
Dim namedRange1 As NamedRange = vstoWorksheet.Controls.AddNamedRange( _
vstoWorksheet.Range("A2", "C4"), "namedRange1")
' The following code will display "$A$2:$C$4".
System.Windows.Forms.MessageBox.Show(namedRange1.Address(True, True, _
Excel.XlReferenceStyle.xlA1, False, ))
' The following code will display "$A2:$C4".
System.Windows.Forms.MessageBox.Show(namedRange1.Address(False, True, _
Excel.XlReferenceStyle.xlA1, False, ))
' The following code will display "R2C1:R4C3".
System.Windows.Forms.MessageBox.Show(namedRange1.Address(True, True, _
Excel.XlReferenceStyle.xlR1C1, False, ))
' The following code will display "R[-1]C[-2]:R[1]C".
System.Windows.Forms.MessageBox.Show(namedRange1.Address(False, False, _
Excel.XlReferenceStyle.xlR1C1, False, vstoWorksheet.Cells(3, 3)))
End Sub
private void DisplayAddress()
{
Worksheet vstoWorksheet = ((Excel.Worksheet)
this.Application.ActiveWorkbook.Worksheets[1]).GetVstoObject();
NamedRange namedRange1 =
vstoWorksheet.Controls.AddNamedRange(vstoWorksheet.Range["A2", "C4"],
"namedRange1");
// The following code will display "$A$2:$C$4".
System.Windows.Forms.MessageBox.Show(namedRange1.Address[true, true,
Excel.XlReferenceStyle.xlA1, false, missing]);
// The following code will display "$A2:$C4".
System.Windows.Forms.MessageBox.Show(namedRange1.Address[false, true,
Excel.XlReferenceStyle.xlA1, false, missing]);
// The following code will display "R2C1:R4C3".
System.Windows.Forms.MessageBox.Show(namedRange1.Address[true, true,
Excel.XlReferenceStyle.xlR1C1, false, missing]);
// The following code will display "R[-1]C[-2]:R[1]C".
System.Windows.Forms.MessageBox.Show(namedRange1.Address[false, false,
Excel.XlReferenceStyle.xlR1C1, false, vstoWorksheet.Cells[3, 3]]);
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
See Also
Reference
Microsoft.Office.Tools.Excel Namespace
Change History
Date |
History |
Reason |
---|---|---|
July 2008 |
Added a version of the code example for an application-level add-in. |
SP1 feature change. |