Compartilhar via


WorkbookBase.SheetChange Event

Definition

Occurs when cells in any worksheet are changed by the user or by an external link.

public:
 event Microsoft::Office::Interop::Excel::WorkbookEvents_SheetChangeEventHandler ^ SheetChange;
public event Microsoft.Office.Interop.Excel.WorkbookEvents_SheetChangeEventHandler SheetChange;
member this.SheetChange : Microsoft.Office.Interop.Excel.WorkbookEvents_SheetChangeEventHandler 
Public Custom Event SheetChange As WorkbookEvents_SheetChangeEventHandler 

Event Type

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.

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(
        Excel.XlReferenceStyle.xlA1);

    MessageBox.Show("The value of " + sheet.Name + ":" +
        changedRange + " was changed.");
}
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

Remarks

This event does not occur on chart sheets.

Applies to