VBA to prevent CUT & Paste function, but allow copy

Steve1208

New Member
Joined
Nov 10, 2017
Messages
28
Hello

I have the code to prevent CUTCOPYPASTE

I need copy to work, because I need to copy the data to outside of excel.

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_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
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi,

Code:
Sub CutStop()
    Application.OnKey "^x", ""
End Sub

Using this code in a module will disable the Ctrl+x (cut) command for that workbook.

It still allows right click - cut however, not sure if this needs disabling too?

EDIT: It will disable the ctrl+x hotkey across all workbooks if that workbook containing the module is open.
 
Last edited:
Upvote 0
Great, thank you.
Although I need cut disabled in all function types:
Cut - Keyboard key short cuts.
Cut - Right click mouse
Cut via the tool bar ribbon

But allow all copy and paste functions
 
Upvote 0
Hey Steve,

You can use this procedure to remove the "Cut" function from the menu that appears upon right clicking a cell:

Code:
Sub RemoveCutFromRightClick()
    Application.CommandBars("Cell").Controls("Cut").Delete
End Sub

I am looking into the final option now (tool bar ribbon) - you could build a custom home tab replicating the built in one except for the cut function, and then hide the built in home tab, showing the custom one instead

EDIT: I think the best way to do the ribbon option is to customize it so that you hide the Clipboard on the Home ribbon tab, then rebuild your own Clipboard section without the Cut function.
 
Last edited:
Upvote 0
Hey Steve,

You can use this procedure to remove the "Cut" function from the menu that appears upon right clicking a cell:

Code:
Sub RemoveCutFromRightClick()
    Application.CommandBars("Cell").Controls("Cut").Delete
End Sub

I am looking into the final option now (tool bar ribbon) - you could build a custom home tab replicating the built in one except for the cut function, and then hide the built in home tab, showing the custom one instead

EDIT: I think the best way to do the ribbon option is to customize it so that you hide the Clipboard on the Home ribbon tab, then rebuild your own Clipboard section without the Cut function.

Thank you again.
However altering the task bar is not an option.
This is a shared document, the document will be used by multiple users someone will cut and paste.
VBA is the way forward with this to protect the document
 
Upvote 0
I'm not so sure if VBA can make changes to the ribbon but I might be wrong, I know you can do it via XML though so that might be an option.

Also if you ever need to re-add the Cut function back to the right-click menu then use this:
Code:
Sub Add_Cut()
    CommandBars("Cell").Controls.Add _
    Type:=msoControlButton, ID:=21, _
    Before:=1
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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