Hi!
I'm having difficulty with a string of code. What I am trying to accomplish is to turn off the cut,copy and paste functions on one worksheet in a workbook. This includes the command bars, right click options and hot keys. The problem is that what I have so far (see below) works for the sheet in question--but when I go to open another workbook--the code still seems to be in effect. Could this be a fluke/program bug? I want to make sure I can remove this oddity--as this sheet goes out to about 70 staff and I will receive endless complaints if they can't see the Edit menu! Please review (admittedly, I have no formal training--everything I know is from trial and error!)
I'm grateful for any help I can get!!! Simplification--or other suggestions!
'******For Cut/Copy/Paste removal--in ThisWorkbook
**I removed the right click issues in the 2007 worksheet itself w/ the following:
I'm having difficulty with a string of code. What I am trying to accomplish is to turn off the cut,copy and paste functions on one worksheet in a workbook. This includes the command bars, right click options and hot keys. The problem is that what I have so far (see below) works for the sheet in question--but when I go to open another workbook--the code still seems to be in effect. Could this be a fluke/program bug? I want to make sure I can remove this oddity--as this sheet goes out to about 70 staff and I will receive endless complaints if they can't see the Edit menu! Please review (admittedly, I have no formal training--everything I know is from trial and error!)
I'm grateful for any help I can get!!! Simplification--or other suggestions!
'******For Cut/Copy/Paste removal--in ThisWorkbook
Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If (Sh.Name = "2007") Then
'Disable Edit menu
Application.CommandBars.FindControl(ID:=30003).Enabled = False
'Disable Copy
Application.CommandBars("Standard").FindControl(ID:=19).Enabled = False
'Disable Cut
Application.CommandBars("Standard").FindControl(ID:=21).Enabled = False
'Disable Paste
Application.CommandBars("Standard").FindControl(ID:=22).Enabled = False
Application.CellDragAndDrop = False
'Disable Ctrl-c (Copy)
Application.OnKey "^c", ""
'Disable Ctrl-x (Cut)
Application.OnKey "^x", ""
'Disable Ctrl-v (Paste)
Application.OnKey "^v", ""
Else
Application.CommandBars.FindControl(ID:=30003).Enabled = True
Application.CommandBars("Standard").FindControl(ID:=19).Enabled = True
Application.CommandBars("Standard").FindControl(ID:=21).Enabled = True
Application.CommandBars("Standard").FindControl(ID:=22).Enabled = True
Application.CellDragAndDrop = True
'Enable Ctrl-c (Copy)
Application.OnKey "^c"
'Enable Ctrl-x (Cut)
Application.OnKey "^x"
'Enable Ctrl-v (Paste)
Application.OnKey "^v"
End If
End Sub
Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
End Sub