This works by disabling the Menu commands and keyboard shortcuts.
I got the idea from code posted by Jim Rech which disabled Cut, Copy
and Cell Drag and Drop.
I extended it to also disable Paste and Paste Special.
It works between different Excel sessions so that something copied in
a different session cannot be pasted in the protected session.
The three Subs are Private so that they can only be run from within
the VBA Editor.
To turn Cut, Copy, Cell Drag and Drop, Paste and Paste Special... off
run CutsOff().
Run CutsOn() to turn them all back on.
Private Sub CutsOff()
AllowCuts False
End Sub
Private Sub CutsOn()
AllowCuts True
End Sub
Private Sub AllowCuts(bEnable As Boolean)
Dim oCtls As CommandBarControls, oCtl As CommandBarControl
Set oCtls = CommandBars.FindControls(ID:=21) 'Cut
If Not oCtls Is Nothing Then
For Each oCtl In oCtls
oCtl.Enabled = bEnable
Next
End If
Set oCtls = CommandBars.FindControls(ID:=19) 'Copy
If Not oCtls Is Nothing Then
For Each oCtl In oCtls
oCtl.Enabled = bEnable
Next
End If
Set oCtls = CommandBars.FindControls(ID:=6002) 'Paste button
If Not oCtls Is Nothing Then
For Each oCtl In oCtls
oCtl.Enabled = bEnable
Next
End If
Set oCtls = CommandBars.FindControls(ID:=22) 'Paste in Edit menu
If Not oCtls Is Nothing Then
For Each oCtl In oCtls
oCtl.Enabled = bEnable
Next
End If
Set oCtls = CommandBars.FindControls(ID:=755) 'Paste Special...
If Not oCtls Is Nothing Then
For Each oCtl In oCtls
oCtl.Enabled = bEnable
Next
End If
''Disable Tools, Options so D&D cannot be restored
Set oCtls = CommandBars.FindControls(ID:=522)
If Not oCtls Is Nothing Then
For Each oCtl In oCtls
oCtl.Enabled = bEnable
Next
End If
With Application
.CellDragAndDrop = bEnable
If bEnable Then
.OnKey "^x"
.OnKey "+{Del}"
.OnKey "^c"
.OnKey "^v"
Else
.OnKey "^x", ""
.OnKey "+{Del}", ""
.OnKey "^c", ""
.OnKey "^v", ""
End If
End With
End Sub
Special thanks to Jim Rech.
Ken Johnson