Event Handler for switching from other applications to Excel?

后端 未结 3 944
心在旅途
心在旅途 2020-12-19 09:42

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:

         


        
3条回答
  •  不思量自难忘°
    2020-12-19 10:31

    I guess after four years you won't have this question in mind still, so I just wanted to convert your comment into a complete answer, so that others have the answer a bit easier. The solution also works in Excel 2016.

    Private Sub Workbook_Open()
        'MsgBox "Opened and disabled"
        Application.CellDragAndDrop = False
    End Sub
    
    Private Sub Workbook_WindowActivate(ByVal Wn As Excel.Window)
        'MsgBox "Activated and disabled"
        Application.CellDragAndDrop = False
    End Sub
    
    Private Sub Workbook_WindowDeactivate(ByVal Wn As Excel.Window)
        'MsgBox "Deactivated and enabled"
        Application.CellDragAndDrop = True
    End Sub
    
    Private Sub Workbook_Before_Close(Cancel As Boolean)
        'MsgBox "Closed and enabled"
        Application.CellDragAndDrop = True
    End Sub
    

    I posted this answer as community wiki, because you deserve the credit actually.

提交回复
热议问题