logo ASAP Utilities

Excel tip: Disable cut, copy and paste

Date: 5 september 2001

Sometimes you might not want your users to cut, copy or paste data in your worksheet.
A good way to do this is to protect all cells, but if you can't do this, for example because they must be able to enter data, this code is a work-around.

The most friendly way to do is, is to run the code when the workbook is activated, and run the "disable" code when the user exits, or switches to another document.


Copy-paste friendly code:
Private Sub Workbook_Activate()
' Add this code in the Workbook_Activate event
' it will load every time the workbook is activated

' Turn off the menu
      Application.CommandBars("Edit").Controls(3).Enabled = False
      Application.CommandBars("Edit").Controls(4).Enabled = False
      Application.CommandBars("Edit").Controls(5).Enabled = False
      Application.CommandBars("Edit").Controls(6).Enabled = False
      ' Turn off the toolbar:
      Application.CommandBars("Standard").Controls(7).Enabled = False
      Application.CommandBars("Standard").Controls(8).Enabled = False
      Application.CommandBars("Standard").Controls(9).Enabled = False
      Application.CommandBars("Standard").Controls(10).Enabled = False
      ' turn off shortcutkeys:
      Application.OnKey "^c", ""
      Application.OnKey "^v", ""
      Application.OnKey "^x", ""
      Application.OnKey "^{INSERT}", ""
      Application.OnKey "+{INSERT}", ""
End Sub

Private Sub Workbook_Deactivate()
' Add this code in the Workbook_Activate event
' it will load every time the workbook is de-activated

' Enable the menu:
      Application.CommandBars("Edit").Controls(3).Enabled = True
      Application.CommandBars("Edit").Controls(4).Enabled = True
      Application.CommandBars("Edit").Controls(5).Enabled = True
      Application.CommandBars("Edit").Controls(6).Enabled = True
      ' Enable the commandbar:
      Application.CommandBars("Standard").Controls(7).Enabled = True
      Application.CommandBars("Standard").Controls(8).Enabled = True
      Application.CommandBars("Standard").Controls(9).Enabled = True
      Application.CommandBars("Standard").Controls(10).Enabled = True
      ' Enable the shortcut keys:
      Application.OnKey "^c"
      Application.OnKey "^v"
      Application.OnKey "^x"
      Application.OnKey "^{INSERT}"
      Application.OnKey "+{INSERT}"
End sub


Private Sub Worksheet_BeforeRightClick(ByVal Target As Excel.Range, Cancel As Boolean)
' Add this code in the Worksheet_BeforeRightClick event
' it will load every time a user right-clicks on the specified worksheet

' To disable the user from "right-clicking" on the userform,
' and therefore not be able to cut, copy or paste

      Cancel = True
End Sub


Note: disabeling cut, copy and paste in the Excel menu with this code does not work in Excel 2007.

Example workbook

example_disable_cutcopypaste.xls (33.00 Kb)



« back

Home Privacy Policy Cookie Policy EULA Download All added Excel tools Sitemap Contact Us


Empowering Excel Users Worldwide for 25 Years