Got any Excel/VBA Questions? Free Excel Help.
While we can stop users cutting/copying cells via Worksheet and/or Workbook protection, this is often at the expense of losing other Excel features that you may still want Excel users to access. The code below can be used to stop users being able to Cut or Copy any cells in the Workbook. However, you must realise that it will only work if the user elects to Enable Macros. No, one cannot force the enabling of macros via VBA.
The code below must be placed in the Private Module of the Workbook Object (This Workbook). To get there easily, right click on the Excel icon, top left next to File and choose View Code. In here paste the code below, close & save and then re-open.
Private Sub Workbook_Activate() Dim oCtrl As Office.CommandBarControl 'Disable all Cut menus For Each oCtrl In Application.CommandBars.FindControls(ID:=21) oCtrl.Enabled = False Next oCtrl 'Disable all Copy menus For Each oCtrl In Application.CommandBars.FindControls(ID:=19) oCtrl.Enabled = False Next oCtrl Application.CellDragAndDrop = False End Sub Private Sub Workbook_Deactivate() Dim oCtrl As Office.CommandBarControl 'Enable all Cut menus For Each oCtrl In Application.CommandBars.FindControls(ID:=21) oCtrl.Enabled = True Next oCtrl 'Enable all Copy menus For Each oCtrl In Application.CommandBars.FindControls(ID:=19) oCtrl.Enabled = True Next oCtrl Application.CellDragAndDrop = True End Sub Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) With Application .CellDragAndDrop = False .CutCopyMode = False 'Clear clipboard End With End Sub
See also:
Free Training Course: Lesson 1 - Excel Fundamentals
See also: Index to Excel VBA Code; Index to Excel Freebies; Lesson 1 - Excel Fundamentals; Index to how to… providing a range of solutions
Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions. Many players are making Excel data sheets with odds for winnings in online casinos in Canada , these files are that shared among other players.