Sheet Deactivate Event Handler

The SheetDeactivate event occurs whenever any sheet within the workbook loses focus. You can write code in the Deactivate event handler of the individual worksheet or, if you want to share the code between all worksheets, within the SheetDeactivate event handler of the workbook. The code example in Listing 7.49 asks users whether they want to save the data in a deactivated worksheet.

Listing 7.49. Saving data when a worksheet is deactivated

Private Sub ThisWorkbook_SheetDeactivate(ByVal Sh As Object) _ Handles Me.SheetDeactivate

Dim Result As Integer = MsgBox( _

"Do you want to save the data in " & _ CType(Sh, Excel.Worksheet).Name.ToString(), _ MsgBoxStyle.YesNo, "Save worksheet")

If Result = vbYes Then

End Sub

0 0

Post a comment