WorkbookBase.SheetChange Event

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.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

Syntax

'Declaration
Public Event SheetChange As WorkbookEvents_SheetChangeEventHandler
public event WorkbookEvents_SheetChangeEventHandler SheetChange

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

See Also

Reference

WorkbookBase Class

Microsoft.Office.Tools.Excel Namespace