I want to activate a workbook when switching from other applications. I'm using Excel 2010.
In the ThisWorkbook object, I've tried the following:
Private Sub Workbook_Activate()
MsgBox "1"
End Sub
Private Sub Workbook_WindowActivate(ByVal Wn As Window)
MsgBox "2"
End Sub
In a class module, I've tried these:
Public WithEvents appevent As Application
Private Sub appevent_ProtectedViewWindowActivate(ByVal Pvw As ProtectedViewWindow)
MsgBox "1"
End Sub
Private Sub appevent_ProtectedViewWindowOpen(ByVal Pvw As ProtectedViewWindow)
MsgBox "2"
End Sub
Private Sub appevent_WindowActivate(ByVal Wb As Workbook, ByVal Wn As Window)
MsgBox "3"
End Sub
Private Sub appevent_WorkbookActivate(ByVal Wb As Workbook)
MsgBox "4"
End Sub
Private Sub appevent_WorkbookDeactivate(ByVal Wb As Workbook)
MsgBox "5"
End Sub
The requirement is to disable the CellDragAndDrop property when this workbook is activated (either clicked-on or alt-tabbed-to) and to re-enable it when this workbook is not active.
See Question&Answers more detail:os