OK. I thought it was the job of setting up the tape at the beginning. I cannot do this with the tape (not to say that this is impossible, but I do not see any MSO commands that will affect this functionality).
An example of your class module (I have not experimented with other view states that you have listed). This module encapsulates an event class and contains application-level event handlers. For this purpose, I think you might only need a WorkbookActivate . The book raising the event will determine whether to enable or disable this property.
Public WithEvents appevent As Application Dim ret As String Private Sub appevent_WorkbookActivate(ByVal wb As Workbook) Call ToggleDragAndDrop(wb, ret) 'Comment out this line when satisfied it is working as expected MsgBox "Cell drag & drop enabled = " & ret End Sub
In a standard module named mod_DragDrop use the following:
Option Explicit Public XLEvents As New cEventClass Sub SetEventHandler() If XLEvents.appevent Is Nothing Then Set XLEvents.appevent = Application End If End Sub Sub ToggleDragAndDrop(wb As Workbook, Optional ret$) Application.CellDragAndDrop = (wb.Name <> ThisWorkbook.Name) ret = Application.CellDragAndDrop End Sub
Put this in the Workbook_Open event handler:
Option Explicit Private Sub Workbook_Open() 'Create the event handler when the workbook opens Call mod_DragDrop.SetEventHandler Call mod_DragDrop.ToggleDragAndDrop(Me) End Sub
Note. If you βfinishβ the runtime or do something during debugging that will result in a loss of state, you will lose an event handler. You can always restore this by calling the Workbook_Open procedure, so adding this to the ThisWorkbook code module can also be extra protection:
Private Sub Workbook_SheetActivate(ByVal Sh As Object) ' Additional safeguard in case state loss has killed the event handler: ' use some workbook-level events to re-instantiate the event handler Call Workbook_Open End Sub
I made a copy of my file on my Google Docs , just in case there is some error in the above code.
source share