Disable cut, copy and paste in Excel from Excel or any other Non-Excel Applications

%3CLINGO-SUB%20id%3D%22lingo-sub-2238431%22%20slang%3D%22en-US%22%3EDisable%20cut%2C%20copy%20and%20paste%20in%20Excel%20from%20Excel%20or%20any%20other%20Non-Excel%20Applications%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2238431%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20seen%20various%20articles%20desribing%20ways%20to%20block%20or%20disable%20cut%2C%20copy%20and%20paste%20in%20Protected%20Excel%20Workbook%20for%20unlocked%20cells%20and%20I%20can%20say%20I%20have%20tried%20almost%20everything.%20The%20most%20appealing%20I%20found%20out%20of%20the%20others%20was%20the%20code%20mentioned%20in%20this%20link%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fwww.extendoffice.com%2Fdocuments%2Fexcel%2F4289-excel-disable-cut-copy-paste.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.extendoffice.com%2Fdocuments%2Fexcel%2F4289-excel-disable-cut-copy-paste.html%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20this%20code%20works%20as%20it%20appeals%20as%20it%20disables%20cut%2C%20copy%20and%20paste%20functionalities%20from%20Excel%20to%20Excel.%3CBR%20%2F%3ELuckily%2C%20I%20happened%20to%20test%20the%20same%20from%20Notepad%20or%20Non-Excel%20aplication%20to%20Excel.%20It%20is%20still%20letting%20copy%20data%20from%20Non-Excel%20Application%20like%20Notepad%20or%20Chrome%20to%20Excel.%3CBR%20%2F%3EI%20am%20not%20an%20expert%20in%20VBA%2C%20so%20if%20there%20is%20anything%20which%20can%20be%20added%20to%20block%20other%20pasting%20options%20it%20would%20great.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECode%20from%20the%20link%20for%20reference%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%20class%3D%22line%20number1%20index0%20alt2%22%3EPrivate%20Sub%20Workbook_Activate()%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number2%20index1%20alt1%22%3EApplication.CutCopyMode%20%3D%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EFalse%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number3%20index2%20alt2%22%3EApplication.OnKey%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%22%5Ec%22%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%22%22%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number4%20index3%20alt1%22%3EApplication.CellDragAndDrop%20%3D%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EFalse%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number5%20index4%20alt2%22%3EEnd%20Sub%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number6%20index5%20alt1%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number7%20index6%20alt2%22%3EPrivate%20Sub%20Workbook_Deactivate()%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number8%20index7%20alt1%22%3EApplication.CellDragAndDrop%20%3D%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3ETrue%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number9%20index8%20alt2%22%3EApplication.OnKey%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%22%5Ec%22%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number10%20index9%20alt1%22%3EApplication.CutCopyMode%20%3D%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EFalse%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number11%20index10%20alt2%22%3EEnd%20Sub%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number12%20index11%20alt1%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number13%20index12%20alt2%22%3EPrivate%20Sub%20Workbook_WindowActivate(ByVal%20Wn%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EAs%20Window)%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number14%20index13%20alt1%22%3EApplication.CutCopyMode%20%3D%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EFalse%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number15%20index14%20alt2%22%3EApplication.OnKey%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%22%5Ec%22%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%22%22%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number16%20index15%20alt1%22%3EApplication.CellDragAndDrop%20%3D%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EFalse%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number17%20index16%20alt2%22%3EEnd%20Sub%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number18%20index17%20alt1%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number19%20index18%20alt2%22%3EPrivate%20Sub%20Workbook_WindowDeactivate(ByVal%20Wn%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EAs%20Window)%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number20%20index19%20alt1%22%3EApplication.CellDragAndDrop%20%3D%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3ETrue%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number21%20index20%20alt2%22%3EApplication.OnKey%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%22%5Ec%22%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number22%20index21%20alt1%22%3EApplication.CutCopyMode%20%3D%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EFalse%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number23%20index22%20alt2%22%3EEnd%20Sub%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number24%20index23%20alt1%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number25%20index24%20alt2%22%3EPrivate%20Sub%20Workbook_SheetSelectionChange(ByVal%20Sh%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EAs%20Object%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EByVal%20Target%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EAs%20Range)%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number26%20index25%20alt1%22%3EApplication.CutCopyMode%20%3D%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EFalse%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number27%20index26%20alt2%22%3EEnd%20Sub%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number28%20index27%20alt1%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number29%20index28%20alt2%22%3EPrivate%20Sub%20Workbook_SheetActivate(ByVal%20Sh%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EAs%20Object)%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number30%20index29%20alt1%22%3EApplication.OnKey%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%22%5Ec%22%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%22%22%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number31%20index30%20alt2%22%3EApplication.CellDragAndDrop%20%3D%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EFalse%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number32%20index31%20alt1%22%3EApplication.CutCopyMode%20%3D%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EFalse%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number33%20index32%20alt2%22%3EEnd%20Sub%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number34%20index33%20alt1%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number35%20index34%20alt2%22%3EPrivate%20Sub%20Workbook_SheetDeactivate(ByVal%20Sh%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EAs%20Object)%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number36%20index35%20alt1%22%3EApplication.CutCopyMode%20%3D%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EFalse%3C%2FDIV%3E%3CDIV%20class%3D%22line%20number37%20index36%20alt2%22%3EEnd%20Sub%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2238431%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2238656%22%20slang%3D%22en-US%22%3ERe%3A%20Disable%20cut%2C%20copy%20and%20paste%20in%20Excel%20from%20Excel%20or%20any%20other%20Non-Excel%20Applications%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2238656%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F885996%22%20target%3D%22_blank%22%3E%40Abdullah_Shurjeel%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20could%20also%20try%20this%3A%20add%20a%20worksheet%20change%20event%20handler%20(or%20a%20workbook_sheetchange%20event%20handler)%20to%20check%20if%20the%20last%20action%20in%20the%20undo%20list%20is%20%22Paste%22%20and%2C%20if%20so%2C%20undo.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EPrivate%20Sub%20Worksheet_Change(ByVal%20Target%20As%20Range)%0A%20%20%20%20%20Const%20procName%20As%20String%20%3D%20%22Worksheet_Change%22%0A%20%20%20%20%20Dim%20lastAction%20As%20String%0A%20%20%20%20%20%0A%20%20%20%20%20%0A%20%20%20%20%20'%2F%2F%20%20Get%20the%20last%20action%20performed%20by%20user.%0A%20%20%20%20%20On%20Error%20Resume%20Next%0A%20%20%20%20%20lastAction%20%3D%20Application.CommandBars(%22Standard%22).Controls(%22%26amp%3BUndo%22).List(1)%0A%20%20%20%20%20On%20Error%20GoTo%20ErrHandler%0A%20%20%20%20%20%0A%20%20%20%20%20'%2F%2F%20%20Check%20if%20the%20last%20action%20was%20paste.%0A%20%20%20%20%20If%20Left(lastAction%2C%205)%20%3D%20%22Paste%22%20Then%0A%20%20%20%20%20%20%20%20%20%20With%20Application%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.EnableEvents%20%3D%20False%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20.Undo%0A%20%20%20%20%20%20%20%20%20%20End%20With%0A%20%20%20%20%20End%20If%0A%0A%0AExitProc%3A%0A%20%20%20%20%20Application.EnableEvents%20%3D%20True%0A%20%20%20%20%20Exit%20Sub%0A%20%20%20%20%20%0AErrHandler%3A%0A%20%20%20%20%20MsgBox%20prompt%3A%3D%22Error%20%22%20%26amp%3B%20Err.Number%20%26amp%3B%20%22%3A%20%22%20%26amp%3B%20Err.Description%2C%20Title%3A%3DMe.Name%20%26amp%3B%20%22.%22%20%26amp%3B%20procName%0A%20%20%20%20%20Resume%20ExitProc%0A%20%20%20%20%20%0AEnd%20Sub%0A%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

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 found out of the others was the code mentioned in this link: https://www.extendoffice.com/documents/excel/4289-excel-disable-cut-copy-paste.html

 

So this code works as it appeals as it disables cut, copy and paste functionalities from Excel to Excel.
Luckily, I happened to test the same from Notepad or Non-Excel aplication to Excel. It is still letting copy data from Non-Excel Application like Notepad or Chrome to Excel.
I am not an expert in VBA, so if there is anything which can be added to block other pasting options it would great.

 

Code from the link for reference:

 

Private Sub Workbook_Activate()
Application.CutCopyMode = False
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
End Sub
 
Private Sub Workbook_Deactivate()
Application.CellDragAndDrop = True
Application.OnKey "^c"
Application.CutCopyMode = False
End Sub
 
Private Sub Workbook_WindowActivate(ByVal Wn As Window)
Application.CutCopyMode = False
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
End Sub
 
Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
Application.CellDragAndDrop = True
Application.OnKey "^c"
Application.CutCopyMode = False
End Sub
 
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Application.CutCopyMode = False
End Sub
 
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
Application.CutCopyMode = False
End Sub
 
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Application.CutCopyMode = False
End Sub
2 Replies

@Abdullah_Shurjeel 

 

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
Thanks 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.