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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
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

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,638
Latest member
Oluwabukunmi

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