I've searched far and wide, and found many examples of how to disable copy and paste. I've got my workbook now so I can't right-click copy, can't ^c to copy, but the menu at the top still works. I've found many examples, and none of them work. I have been fighting this for 2 days straight. Beofre I lose my mind, could someone please help me out with this. Here is what I have so far:
Code:
Private Sub Workbook_Open()
UserForm1.Show
End Sub
Private Sub Workbook_Activate()
DisableCutAndPaste
End Sub
Private Sub DisableCutAndPaste()
' 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", ""
End Sub
Sub lastrow()
Range("A1").End(xlDown).Select
End Sub
Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Cancel = True
Dim ans, password
password = "12345"
ReStart_Here:
ans = InputBox("Cut, Copy and Paste have been disabled. Enter password or hit cancel")
If ans <> password Then
ans = MsgBox("Invalid password", vbRetryCancel)
End If
If ans = vbRetry Then
GoTo ReStart_Here
End If
If ans = password Then
MsgBox ("Copy and Paste is now allowed. Close the worksheet to disable again")
EnableCutAndPaste
End If
End Sub
Private Sub EnableCutAndPaste()
EnableControl 21, True ' cut
EnableControl 19, True ' copy
EnableControl 22, True ' paste
EnableControl 755, True ' pastespecial
Application.OnKey "^c"
Application.OnKey "^v"
Application.OnKey "+{DEL}"
Application.OnKey "+{INSERT}"
Application.CellDragAndDrop = True
End Sub
Private Sub EnableControl(Id As Integer, Enabled As Boolean)
Dim CB As CommandBar
Dim C As CommandBarControl
On Error Resume Next
For Each CB In Application.CommandBars
Set C = CB.FindControl(Id:=Id, recursive:=True)
If Not C Is Nothing Then C.Enabled = Enabled
Next
Application.EnableEvents = False
End Sub