Worksheet.Change Event (2007 System)
Occurs when something changes in the Worksheet cells.
Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)
Syntax
'Declaration
Public Event Change As DocEvents_ChangeEventHandler
'Usage
Dim instance As Worksheet
Dim handler As DocEvents_ChangeEventHandler
AddHandler instance.Change, handler
public event DocEvents_ChangeEventHandler Change
public:
event DocEvents_ChangeEventHandler^ Change {
void add (DocEvents_ChangeEventHandler^ value);
void remove (DocEvents_ChangeEventHandler^ value);
}
JScript does not support events.
Remarks
This event does not occur when cells change during a recalculation.
Examples
The following code example demonstrates a handler for the Change event that displays the name of the worksheet and the range of cells that were changed.
This example is for a document-level customization.
Sub Worksheet1_Change(ByVal Target As Excel.Range) _
Handles Me.Change
Dim changedRange As String = Target.Address( _
ReferenceStyle:=Excel.XlReferenceStyle.xlA1)
MsgBox("The value of " & Me.Name & ":" & changedRange & " has been changed.")
End Sub
private void WorksheetChange()
{
this.Change +=
new Excel.DocEvents_ChangeEventHandler(
Worksheet1_Change);
}
void Worksheet1_Change(Excel.Range Target)
{
string changedRange = Target.get_Address(missing, missing,
Excel.XlReferenceStyle.xlA1, missing, missing);
MessageBox.Show("The value of " + this.Name + ":" +
changedRange + " has been changed.");
}
.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.