diable copy from menu

itbman

New Member
Joined
May 29, 2008
Messages
17
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
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Just out of curiosity, why do you need to disable copy/cut/paste? Is there another way you can "lock" the user out of your data?
 
Upvote 0
Just out of curiosity, why do you need to disable copy/cut/paste? Is there another way you can "lock" the user out of your data?

it's just one of the security measures my boss wanted. I'm just being a good little peon and doing as told.
 
Upvote 0
Maybe

Code goes in Thisworkbook

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim Opt As Object
    Dim TB As Object
     
    Set TB = Application.CommandBars("Worksheet Menu Bar").Controls("Edit")
    Set Opt = TB.Controls("Copy")
    Opt.Enabled = True
     
End Sub

Code:
Sub x()
    Dim Opt As Object
    Dim TB As Object
     
    Set TB = Application.CommandBars("Worksheet Menu Bar").Controls("Edit")
    Set Opt = TB.Controls("Copy")
    Opt.Enabled = True
     
End Sub

VBA Noob
 
Upvote 0

Forum statistics

Threads
1,215,200
Messages
6,123,604
Members
449,109
Latest member
Sebas8956

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top