Disable cut/paste in ribbon and short cut

chrism1

New Member
Joined
Mar 20, 2012
Messages
12
<TABLE style="BORDER-BOTTOM: rgb(228,237,246) 1px solid; BORDER-LEFT: rgb(228,237,246) 1px solid; WIDTH: 98%; BORDER-TOP: rgb(228,237,246) 1px solid; BORDER-RIGHT: rgb(228,237,246) 1px solid" cellSpacing=0 align=center><TBODY><TR><TD>



</TD></TR><TR><TD></TD></TR><TR><TD style="BACKGROUND: rgb(228,237,246)"></TD></TR></TBODY></TABLE>
The following code will disable copy/paste from both the short cut keys and ribbon. It includes a message box to notify the user that right click has been disabled. I would like to know how to add code to include a message box to notify the user that cut/copy has been disabled when the shortcut keys (control x/control c) are used. I have tried various things, but am not skilled in this area. Thank you!

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 <!-- / message --><!-- sig --><!-- / message --><!-- sig -->
 
Last edited:

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
You could have two macros like this...

Code:
Sub CtrlC()
    MsgBox "The shortcut 'Ctrl+C' has been disabled. ", , "Disabled Shortcut"
End Sub

Sub CtrlX()
    MsgBox "The shortcut 'Ctrl+X' has been disabled. ", , "Disabled Shortcut"
End Sub

...then assign the shortcuts Ctrl+c and Ctrl+x to these macros. This would re-assign the usual cut/copy shortcuts to these two macros that display a message instead of performing a cut/copy.

Also, you don't need this...
Code:
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_SheetActivate(ByVal Sh As Object)
Application.OnKey "^c", ""
Application.CellDragAndDrop = False
Application.CutCopyMode = False
End Sub
 
Last edited:
Upvote 0
AlphaFrog-

Thank you for your help.

Based on your response, I now have the following code:

Sub CtrlC()
MsgBox "The shortcut 'Ctrl+C' has been disabled. ", , "Disabled Shortcut"
End Sub

Sub CtrlX()
MsgBox "The shortcut 'Ctrl+X' has been disabled. ", , "Disabled Shortcut"
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_SheetDeactivate(ByVal Sh As Object)
Application.CutCopyMode = False
End Sub

I assigned shortcut keys for control x and c to the macros. The spreadsheet does now allow for cutting/pasting, etc. from either the ribbon or shortcut keys. However, it does not provide a message when control x or c are used.

If I run the macro (view, macros, view macros, select macro name, run) from the ribbon, the message does pop up.

Do you know what I am doing incorrectly? I apologize for what is probbaly a simple anwer. I am not familiar with this area and have not been able to figure it out by researching the internet.

Thank you again for your help!
 
Upvote 0
I assigned shortcut keys for control x and c to the macros. The spreadsheet does now allow for cutting/pasting, etc. from either the ribbon or shortcut keys. However, it does not provide a message when control x or c are used.

If I run the macro (view, macros, view macros, select macro name, run) from the ribbon, the message does pop up.

Is now a typo? Did you mean now or not?

Where are the two macros (CtrlC and CtrlX) located? They should be in a standard module like Module1 and not within a worksheet module.
 
Upvote 0
The code that you removed had left Excel in a state where the shortcuts Ctrl+c and Ctrl+x are disabled. If you restart Excel, the two shortcuts should work again, and they are assigned to the two new macros.
 
Upvote 0
Is now a typo? Did you mean now or not?

Where are the two macros (CtrlC and CtrlX) located? They should be in a standard module like Module1 and not within a worksheet module.

AlphaFrog,

Now was a typo. Should have been not. I fixed my workbook as you noted and it works exactly as I wanted. Cut/paste is disabled from both the ribbon and the shortcut keys. However, I have now noticed users are still able to paste via the clipboard. Could you point me in the direction of how to remedy this? Also, it is my understanding none of this will work if the user disables macros. Is there any way to force the use of macros?

Thank you so much for your help with this. I have searched the internet for quite some time and have not been able to find one code that addresses everything and am not skilled enough to combine multiple codes.
 
Upvote 0
AlphaFrog:

I found this same post when trying to solve my question. It does prevent right clicking to cut/copy, using shortcuts ctrl c/x, disables clipboard (grays the option out). However, it does not stop cutting and pasting from the ribbon, unless I am doing something incorrectly. The forum post says it has been tested on Excel 2000, 2003 and 2007. I am using 2010, though as I noted, the other disabling functions do work.

Thank you!
 
Upvote 0
Also, I previously found the post you referenced to force macros, but was never able to get it to work. The post notes it was texted with Excel 2003. I am using 2010, but do not know if this is what causes it not to work, or if I am doing it incorrectly. Thank you for your time.
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,108
Members
452,302
Latest member
TaMere

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