Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. Private Sub Workbook_Activate()
  2. MsgBox "1"
  3. End Sub
  4.  
  5. Private Sub Workbook_WindowActivate(ByVal Wn As Window)
  6. MsgBox "2"
  7. End Sub
  8.  
  9. Public WithEvents appevent As Application
  10. Private Sub appevent_ProtectedViewWindowActivate(ByVal Pvw As ProtectedViewWindow)
  11. MsgBox "1"
  12. End Sub
  13.  
  14. Private Sub appevent_ProtectedViewWindowOpen(ByVal Pvw As ProtectedViewWindow)
  15. MsgBox "2"
  16. End Sub
  17.  
  18. Private Sub appevent_WindowActivate(ByVal Wb As Workbook, ByVal Wn As Window)
  19. MsgBox "3"
  20. End Sub
  21.  
  22. Private Sub appevent_WorkbookActivate(ByVal Wb As Workbook)
  23. MsgBox "4"
  24. End Sub
  25.  
  26. Private Sub appevent_WorkbookDeactivate(ByVal Wb As Workbook)
  27. MsgBox "5"
  28. End Sub
  29.  
  30. Public WithEvents appevent As Application
  31. Dim ret As String
  32. Private Sub appevent_WorkbookActivate(ByVal wb As Workbook)
  33.  
  34. Call ToggleDragAndDrop(wb, ret)
  35. 'Comment out this line when satisfied it is working as expected
  36. MsgBox "Cell drag & drop enabled = " & ret
  37. End Sub
  38.  
  39. Option Explicit
  40. Public XLEvents As New cEventClass
  41. Sub SetEventHandler()
  42.  
  43. If XLEvents.appevent Is Nothing Then
  44. Set XLEvents.appevent = Application
  45. End If
  46.  
  47. End Sub
  48.  
  49. Sub ToggleDragAndDrop(wb As Workbook, Optional ret$)
  50.  
  51. Application.CellDragAndDrop = (wb.Name <> ThisWorkbook.Name)
  52. ret = Application.CellDragAndDrop
  53. End Sub
  54.  
  55. Option Explicit
  56. Private Sub Workbook_Open()
  57. 'Create the event handler when the workbook opens
  58. Call mod_DragDrop.SetEventHandler
  59. Call mod_DragDrop.ToggleDragAndDrop(Me)
  60.  
  61. End Sub
  62.  
  63. Private Sub Workbook_SheetActivate(ByVal Sh As Object)
  64. ' Additional safeguard in case state loss has killed the event handler:
  65. ' use some workbook-level events to re-instantiate the event handler
  66.  
  67. Call Workbook_Open
  68. End Sub
  69.  
  70. Private Sub Workbook_Open()
  71. 'MsgBox "Opened and disabled"
  72. Application.CellDragAndDrop = False
  73. End Sub
  74.  
  75. Private Sub Workbook_WindowActivate(ByVal Wn As Excel.Window)
  76. 'MsgBox "Activated and disabled"
  77. Application.CellDragAndDrop = False
  78. End Sub
  79.  
  80. Private Sub Workbook_WindowDeactivate(ByVal Wn As Excel.Window)
  81. 'MsgBox "Deactivated and enabled"
  82. Application.CellDragAndDrop = True
  83. End Sub
  84.  
  85. Private Sub Workbook_Before_Close(Cancel As Boolean)
  86. 'MsgBox "Closed and enabled"
  87. Application.CellDragAndDrop = True
  88. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement