Forum Discussion
Abdullah_Shurjeel
Mar 26, 2021Copper Contributor
Disable cut, copy and paste in Excel from Excel or any other Non-Excel Applications
I have seen various articles desribing ways to block or disable cut, copy and paste in Protected Excel Workbook for unlocked cells and I can say I have tried almost everything. The most appealing I f...
JMB17
Mar 26, 2021Bronze Contributor
You could also try this: add a worksheet change event handler (or a workbook_sheetchange event handler) to check if the last action in the undo list is "Paste" and, if so, undo.
Private Sub Worksheet_Change(ByVal Target As Range)
Const procName As String = "Worksheet_Change"
Dim lastAction As String
'// Get the last action performed by user.
On Error Resume Next
lastAction = Application.CommandBars("Standard").Controls("&Undo").List(1)
On Error GoTo ErrHandler
'// Check if the last action was paste.
If Left(lastAction, 5) = "Paste" Then
With Application
.EnableEvents = False
.Undo
End With
End If
ExitProc:
Application.EnableEvents = True
Exit Sub
ErrHandler:
MsgBox prompt:="Error " & Err.Number & ": " & Err.Description, Title:=Me.Name & "." & procName
Resume ExitProc
End Sub
- Abdullah_ShurjeelMar 27, 2021Copper ContributorThanks for the response.
I tried the code but it is still letting paste from non-excel application to my working excel when I right click and paste with source formatting that is even removing formatting.
Note: Control + V is getting disable but not right click.