共用方式為


NamedRange.Change Event

Definition

Occurs when something changes in the NamedRange control.

public:
 event Microsoft::Office::Interop::Excel::DocEvents_ChangeEventHandler ^ Change;
event Microsoft.Office.Interop.Excel.DocEvents_ChangeEventHandler Change;
member this.Change : Microsoft.Office.Interop.Excel.DocEvents_ChangeEventHandler 
Event Change As DocEvents_ChangeEventHandler 

Event Type

Examples

The following code example creates a NamedRange and a Change event handler. To raise the Change event, add text to one of the cells in the NamedRange and then press ENTER.

This version is for a document-level customization.

Microsoft.Office.Tools.Excel.NamedRange changesRange;
private void NotifyChanges()
{
    changesRange = this.Controls.AddNamedRange(
        this.Range["B2", "E5"], "compositeRange");
    changesRange.Change += new Microsoft.Office.Interop.Excel.
        DocEvents_ChangeEventHandler(changesRange_Change);
}

void changesRange_Change(Excel.Range Target)
{
    string cellAddress = Target.get_Address(
        Microsoft.Office.Interop.Excel.XlReferenceStyle.xlA1);
    MessageBox.Show("Cell " + cellAddress + " changed.");
}
Private changesRange As Microsoft.Office.Tools.Excel.NamedRange

Private Sub NotifyChanges()
    changesRange = Me.Controls.AddNamedRange( _
        Me.Range("B2", "E5"), "compositeRange")
    AddHandler changesRange.Change, _
        AddressOf changesRange_Change
End Sub


Sub changesRange_Change(ByVal Target As Excel.Range)
    Dim cellAddress As String = Target.Address(, , _
        Microsoft.Office.Interop.Excel.XlReferenceStyle.xlA1, , )
    MessageBox.Show("Cell " & cellAddress & " changed.")
End Sub

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

Remarks

This event is raised if the NamedRange control is changed by either a programmatic modification or user interaction. This event does not occur when cells in a NamedRange control change during a recalculation.

Applies to