Hello everyone! So I'm running into a few roadblocks trying to prevent people from pasting anything other than "values" only, as well as preventing people from using the Cut option. I have my worksheet locked, but multiple people are copying cells with various formatting (ie: cell background colors/fills), and the formatting is carrying over to my workbook and it is over-riding my conditional formatting. I've spent yesterday afternoon and this morning surfing the Internet for ways to prevent cutting and pasting, and so far I have found several macros out there, but none appear to stop any "work-arounds" for people that are trying to cut or use any other paste methods. At this point, I have successfully prevented the ability to do the CTRL + V and CTRL + X key combinations to prevent cutting and pasting that way, left-clicking a cell now automatically pastes the value only of anything on the clipboard, and it appears that the Cut method is now disabled when right-clicking on a cell with a value..... but I can still right-click a cell and choose any paste method I want, and the Cut and various Paste options are still available and functional from the Home ribbon.
I can't seem to find anything out there that successfully prevents the Cut and the Paste options from the right-click menu as well as the Home ribbon. Is anyone able to assist with this please? Training the various people using this spreadsheet to be sure to not use any other paste options is unfortunately out of the question, due to the over-whelming volume of people using my workbook.
Here is the code I'm currently using so far:
In a standard module:
Option Explicit
Sub ToggleCutAndPaste(Allow As Boolean)
'Activate/deactivate cut, copy, paste and pastespecial menu items
Call EnableMenuItem(21, False) ' cut
Call EnableMenuItem(22, False) ' paste
Call EnableMenuItem(755, False) ' pastespecial
'Activate/deactivate drag and drop ability
Application.CellDragAndDrop = False
'Activate/deactivate cut, copy, paste and pastespecial shortcut keys
With Application
Select Case Allow
Case Is = False
.OnKey "^v", "CutPasteDisabled"
.OnKey "^x", "CutPasteDisabled"
.OnKey "+{DEL}", "CutPasteDisabled"
.OnKey "^{INSERT}", "CutPasteDisabled"
Case Is = True
.OnKey "^v"
.OnKey "^x"
.OnKey "+{DEL}"
.OnKey "^{INSERT}"
End Select
End With
End Sub
Sub EnableMenuItem(ctlId As Integer, Enabled As Boolean)
'Activate/Deactivate specific menu item
Dim cBar As CommandBar
Dim cBarCtrl As CommandBarControl
For Each cBar In Application.CommandBars
Set cBarCtrl = cBar.FindControl(ID:=ctlId, recursive:=False)
Next
End Sub
Sub CutPasteDisabled()
MsgBox "Cutting and standard pasting have been disabled in this workbook."
End Sub
In "ThisWorkbook":
Sub Del_Item()
CommandBars("Cell").Controls("Cut").Delete
CommandBars("Cell").Controls("Paste").Delete
End Sub
Private Sub Workbook_Activate()
Call ToggleCutAndPaste(False)
End Sub
Private Sub Workbook_Deactivate()
Call ToggleCutAndPaste(True)
End Sub
Private Sub Workbook_Open()
Call ToggleCutAndPaste(False)
Application.CommandBars("Standard").FindControl(ID:=21).Enabled = False
Application.CommandBars("Standard").FindControl(ID:=22).Enabled = False
Application.CommandBars("Standard").FindControl(ID:=755).Enabled = False
Application.CommandBars("Standard").FindControl(ID:=19).Enabled = False
Application.CommandBars("Standard").Controls("Paste").Enabled = False
Application.CommandBars("Edit").Enabled = False
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call ToggleCutAndPaste(True)
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
On Error Resume Next
Target.PasteSpecial xlPasteValues
Application.CutCopyMode = True
End Sub
Any solid help would be really appreciated, as the various disabling of the "CommandBars" does not seem to be successfully disabling things everywhere. Thanks so much!
Bookmarks