Workbook.SheetChange Event (2007 System)
Occurs when cells in any worksheet are changed by the user or by an external link.
Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)
Syntax
'Declaration
Public Event SheetChange As WorkbookEvents_SheetChangeEventHandler
'Usage
Dim instance As Workbook
Dim handler As WorkbookEvents_SheetChangeEventHandler
AddHandler instance.SheetChange, handler
public event WorkbookEvents_SheetChangeEventHandler SheetChange
public:
event WorkbookEvents_SheetChangeEventHandler^ SheetChange {
void add (WorkbookEvents_SheetChangeEventHandler^ value);
void remove (WorkbookEvents_SheetChangeEventHandler^ value);
}
JScript does not support events.
Remarks
This event does not occur on chart sheets.
Examples
The following code example demonstrates a handler for the SheetChange event. The event handler displays the name of the worksheet and the range of cells that were changed.
This example is for a document-level customization.
Sub ThisWorkbook_SheetChange(ByVal Sh As Object, _
ByVal Target As Excel.Range) Handles Me.SheetChange
Dim Sheet1 As Excel.Worksheet = CType(Sh, Excel.Worksheet)
Dim ChangedRange As String = Target.Address( _
ReferenceStyle:=Excel.XlReferenceStyle.xlA1)
MsgBox("The value of " & Sheet1.Name & ":" & ChangedRange & _
" was changed.")
End Sub
private void WorkbookSheetChange()
{
this.SheetChange += new
Excel.WorkbookEvents_SheetChangeEventHandler(
ThisWorkbook_SheetChange);
}
void ThisWorkbook_SheetChange(object Sh, Excel.Range Target)
{
Excel.Worksheet sheet = (Excel.Worksheet)Sh;
string changedRange = Target.get_Address(missing, missing,
Excel.XlReferenceStyle.xlA1, missing, missing);
MessageBox.Show("The value of " + sheet.Name + ":" +
changedRange + " was 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.