NamedRange.SelectionChange Event
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Occurs when the selection inside the NamedRange control changes.
public:
event Microsoft::Office::Interop::Excel::DocEvents_SelectionChangeEventHandler ^ SelectionChange;
event Microsoft.Office.Interop.Excel.DocEvents_SelectionChangeEventHandler SelectionChange;
member this.SelectionChange : Microsoft.Office.Interop.Excel.DocEvents_SelectionChangeEventHandler
Event SelectionChange As DocEvents_SelectionChangeEventHandler
Event Type
Examples
The following code example demonstrates a handler for the SelectionChange event that displays the address of a cell that is selected in the NamedRange.
This version is for a document-level customization.
Microsoft.Office.Tools.Excel.NamedRange selectionChangeRange;
private void DisplaySelectionChange()
{
selectionChangeRange = this.Controls.AddNamedRange(
this.Range["A1", "E5"], "selectionChangeRange");
this.selectionChangeRange.SelectionChange += new
Microsoft.Office.Interop.Excel.
DocEvents_SelectionChangeEventHandler(
selectionChangeRange_SelectionChange);
}
void selectionChangeRange_SelectionChange(
Microsoft.Office.Interop.Excel.Range Target)
{
string selectedRange = Target.get_Address(
Excel.XlReferenceStyle.xlA1);
MessageBox.Show(this.Name + ": " + selectedRange +
" raised the SelectionChange event.");
}
Private selectionChangeRange As Microsoft.Office.Tools.Excel.NamedRange
Private Sub DisplaySelectionChange()
selectionChangeRange = Me.Controls.AddNamedRange( _
Me.Range("A1", "E5"), "selectionChangeRange")
AddHandler Me.selectionChangeRange.SelectionChange, _
AddressOf selectionChangeRange_SelectionChange
End Sub
Sub selectionChangeRange_SelectionChange(ByVal Target As _
Microsoft.Office.Interop.Excel.Range)
Dim selectedRange As String = Target.Address(, , _
Excel.XlReferenceStyle.xlA1, , )
MessageBox.Show(Me.Name & ": " & selectedRange & _
" raised the SelectionChange event.")
End Sub
This version is for an application-level add-in.
Remarks
This event is raised when the selection changes to or within the NamedRange control.