Disable Cut or Copy or Paste in Excel

sree_31

Board Regular
Joined
Apr 18, 2002
Messages
63
I want to disable cut or copy or paste in a worksheet as soon as the workbook is opened

Can someone help
 
In addition to Ivan's fine code with command bars, here is an alternative approach that can be placed in the workbook module to cover cut, copy, paste, and drag & drop:


Private Sub Workbook_Activate()
Application.CutCopyMode = False
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
End Sub

Private Sub Workbook_Deactivate()
Application.CellDragAndDrop = True
Application.OnKey "^c"
Application.CutCopyMode = False
End Sub

Private Sub Workbook_WindowActivate(ByVal Wn As Window)
Application.CutCopyMode = False
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
End Sub

Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
Application.CellDragAndDrop = True
Application.OnKey "^c"
Application.CutCopyMode = False
End Sub

Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Cancel = True
MsgBox "Right click menu deactivated." & vbCrLf & _
"Cannot copy or ''drag & drop''.", 16, "For this workbook:"
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Application.CutCopyMode = False
End Sub

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
Application.CutCopyMode = False
End Sub

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Application.CutCopyMode = False
End Sub


How do I deactivate copy, paste from excel to another application, I just copy and paste this code, but this only work in excel, I want to avoid people copy from excel and paste in notepad or any other word processor.

Thanks in advance
Capricorn1228
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
This has helped me a lot Tom.... Hats off to you :)
In addition to Ivan's fine code with command bars, here is an alternative approach that can be placed in the workbook module to cover cut, copy, paste, and drag & drop:


Private Sub Workbook_Activate()
Application.CutCopyMode = False
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
End Sub

Private Sub Workbook_Deactivate()
Application.CellDragAndDrop = True
Application.OnKey "^c"
Application.CutCopyMode = False
End Sub

Private Sub Workbook_WindowActivate(ByVal Wn As Window)
Application.CutCopyMode = False
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
End Sub

Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
Application.CellDragAndDrop = True
Application.OnKey "^c"
Application.CutCopyMode = False
End Sub

Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Cancel = True
MsgBox "Right click menu deactivated." & vbCrLf & _
"Cannot copy or ''drag & drop''.", 16, "For this workbook:"
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Application.CutCopyMode = False
End Sub

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
Application.CutCopyMode = False
End Sub

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Application.CutCopyMode = False
End Sub
 
Upvote 0
Ivan F Moala has this on his website. check it out at Website Disabled

hth

edit: link

Hello, as this post is already 10 years old. The code Mr. Ivan F Moala provided on his website is already disabled/expired. Tom Urtis's code is working very fine but I still can copy, paste, etc using the command bar. What I would like to completely disable the copy and paste.

Thanks!
 
Last edited:
Upvote 0
I just used the Custom UI Editor to remove those commands. There may be a better way to do it, but it was the easiest solution I found.
 
Upvote 0
It is a very useful code , but I am asking can I have a macro to stop this macro if I want ?
 
Upvote 0
Hi, I was looking at a way of doing this but all the above seemed a bit convoluted, and actually did not work completely for me. So I tried a different avenue. My thinking was that if they can see on the screen already, then I have no need to protect (they could always do a screen dump or digital photo with OCR and get the info anyway). My main concern was to protect what they can't see (hidden rows and columns). So I used the Selection change event to trigger a macro that changed what ever selection was made to "Visible cells only". I had to trap a few errors along the way but seems to work fine. Some of you gurus may be able to fine tune or comment.
Thanks.
Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)On Error GoTo OflowMsg
    If Selection.Count > 1 And Selection.Count Then
        Selection.SpecialCells(xlCellTypeVisible).Select
    End If
Exit Sub
OflowMsg:
    If Err.Number = 6 Then
        MsgBox ("Overflow Error. Please select fewer cells")
        Range("a1").Select
    End If
    If Err.Number = 440 Then
        Range("a1").Select
    End If
 
Upvote 0
Hi Friends, how i ca give a pirticular columns (like columns A) to disable copy paste. rest columns can be copied and pasted
 
Upvote 0
Hi Friends, how i ca give a pirticular columns (like columns A) to disable copy paste. rest columns can be copied and pasted

Just use the code above and put an if statement to only activate if a specific column is selected. Not sure of the code.
 
Upvote 0

Forum statistics

Threads
1,213,554
Messages
6,114,280
Members
448,562
Latest member
Flashbond

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