Sheet Activate Event Handler

The SheetActivate event is raised whenever a worksheet in the workbook is activated. Because each of the VSTO worksheets also has an ActivateEvent event, you write code here to capture the event for any of the worksheets. The code in Listing 7.48 displays the name of the active worksheet, along with its code name, in the status bar. To test this code, change the name of a worksheet, and then deactivate and reactivate it.

Listing 7.48. Displaying the active worksheet in the status bar

Private Sub ThisWorkbook_SheetActivate(ByVal Sh As Object) _ Handles Me.SheetActivate

Dim Worksheet As Excel.Worksheet = CType(Sh, Excel.Worksheet) Application.StatusBar = "The worksheet " & _ Worksheet.Name & " (code name " & _ CStr(Worksheet.CodeName) & ") is active."

End Sub

0 0

Post a comment