I am using VBA with Excel 2010. I am familiar with creating event handling procedures at the worksheet and workbook levels (as well as smaller objects such as UserForm or various controls). I want to capture an Activate event when the user switches to another application, and then comes back (activates) Excel. The worksheet activate event does not fire, because I'm not changing the active sheet (nor do I want to). Nor does the workbook activate event, because I'm not changing active workbooks.
I have created a class module to try capture the event. It works when I first open Excel, but then fails to run when I leave and come back to Excel. Here is the code:
' ••cls_mdlExcelEvents Class Module••
Private WithEvents App As Application
Option Explicit
Private Sub Class_Initialize()
Set App = Application
End Sub
Private Sub App_WindowActivate(ByVal Wb As Workbook, ByVal Wn As Window)
MsgBox "It Works!", vbOKOnly, "Test"
End Sub
Here is the reference to my class module from my ThisWorkbook module:
' ••ThisWorkbook Module••
Private xlApp As cls_mdlExcelEvents
Option Explicit
' •Workbook_Open Event Handler•
Private Sub Workbook_Open()
Set xlApp = New cls_mdlExcelEvents
End Sub
Bookmarks