Udostępnij za pośrednictwem


NamedRange.End Property (2007 System)

Gets a Range that represents the cell at the end of the region that contains 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 End As NamedRange._EndType
'Usage
Dim instance As NamedRange 
Dim value As NamedRange._EndType 

value = instance.End
[BrowsableAttribute(false)]
public NamedRange._EndType End { get; }
[BrowsableAttribute(false)]
public:
property NamedRange._EndType^ End {
    NamedRange._EndType^ get ();
}
public function get End () : NamedRange._EndType

Property Value

Type: Microsoft.Office.Tools.Excel.NamedRange._EndType
A Range that represents the cell at the end of the region that contains the NamedRange control.

Remarks

The End property is intended to be used with the following parameter.

Parameter

Description

Direction

One of the XlDirection values that indicates the direction in which to find the last cell.

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

This property is equivalent to pressing END+UP ARROW, END+DOWN ARROW, END+LEFT ARROW, or END+RIGHT ARROW.

Examples

The following code example creates a NamedRange and then populates a cell to the right to create a boundary for the region of blank columns. It then displays a message box asking if you want to select the end of the region to the right of the NamedRange.

This version is for a document-level customization.

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

Private Sub SelectEnd()
    endRange = Me.Controls.AddNamedRange( _
        Me.Range("B1", "D4"), "endRange")
    Me.Range("H1").Value2 = 123
    endRange.Select()
    If MessageBox.Show("Select end of region to the right?", _
        "End of Region Test", MessageBoxButtons.OKCancel) = _
        DialogResult.OK Then 
        Me.endRange.End(Excel.XlDirection.xlToRight).Select()
    End If 
End Sub
Microsoft.Office.Tools.Excel.NamedRange endRange;
private void SelectEnd()
{
    endRange = this.Controls.AddNamedRange(
        this.Range["B1", "D4"], "endRange");
    this.Range["H1", missing].Value2 = 123;
    endRange.Select();
    if (MessageBox.Show("Select end of region to the right?", 
        "End of Region Test", MessageBoxButtons.OKCancel) == DialogResult.OK)
    {
        this.endRange.End[Excel.XlDirection.xlToRight].Select();
    }
} 

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

Private endRange As NamedRange

Private Sub SelectEnd()
    Dim vstoWorksheet As Worksheet = CType( _
        Me.Application.ActiveWorkbook.Worksheets(1),  _
        Excel.Worksheet).GetVstoObject()
    endRange = vstoWorksheet.Controls.AddNamedRange( _
        vstoWorksheet.Range("B1", "D4"), "endRange")
    vstoWorksheet.Range("H1").Value2 = 123
    endRange.Select()
    If System.Windows.Forms.MessageBox.Show( _
        "Select end of region to the right?", _
        "End of Region Test", _
        System.Windows.Forms.MessageBoxButtons.OKCancel) = _
        System.Windows.Forms.DialogResult.OK Then 
        Me.endRange.End(Excel.XlDirection.xlToRight).Select()
    End If 
End Sub
NamedRange endRange;
private void SelectEnd()
{
    Worksheet vstoWorksheet = ((Excel.Worksheet)
        this.Application.ActiveWorkbook.Worksheets[1]).GetVstoObject();
    endRange = vstoWorksheet.Controls.AddNamedRange(
        vstoWorksheet.Range["B1", "D4"], "endRange");
    vstoWorksheet.Range["H1", missing].Value2 = 123;
    endRange.Select();
    if (System.Windows.Forms.MessageBox.Show(
        "Select end of region to the right?",
        "End of Region Test", 
        System.Windows.Forms.MessageBoxButtons.OKCancel) ==
        System.Windows.Forms.DialogResult.OK)
    {
        this.endRange.End[Excel.XlDirection.xlToRight].Select();
    }
}

.NET Framework Security

See Also

Reference

NamedRange Class

NamedRange Members

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.