CutCopyPaste mode - will not deactivate

Helix242

Board Regular
Joined
Jun 28, 2016
Messages
78
Hi all,

I'm sure this is a simple fix, but I have a code to turn off the past options, however they do not reactive once clicked off that workbook and remain activated on all other books. Can anyone explain my error? :confused:
Code:
Private Sub Worksheet_Activate()
Application.CutCopyMode = False
Application.CommandBars("cell").Controls("Paste").Visible = False
Application.CommandBars("cell").Controls("Paste Special...").Visible = False
Application.OnKey "^v", ""
End Sub


Private Sub Worksheet_Deactivate()
Application.CutCopyMode = True
Application.CommandBars("cell").Controls("Paste").Visible = True
Application.CommandBars("cell").Controls("Paste Special...").Visible = True
Application.OnKey "^v"
End Sub
Thank you.
 
Last edited by a moderator:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Those events are only triggered by switching sheets within a workbook. If you are selecting a different workbook, you need the Workbook_Activate and Deactivate events, which must be set in the ThisWorkbook module.
 
Upvote 0
Those events are only triggered by switching sheets within a workbook. If you are selecting a different workbook, you need the Workbook_Activate and Deactivate events, which must be set in the ThisWorkbook module.

Hi Rory,

Thank you for this. I have amended the code and put it in ThisWorkbook, but this does not appear to be Activating at all, with all Paste options being visible.

Many thanks
Code:
Private Sub Workbook_Activate()
Application.CutCopyMode = False
Application.CommandBars("cell").Controls("Paste").Visible = False
Application.CommandBars("cell").Controls("Paste Special...").Visible = False
Application.OnKey "^v", ""
End Sub




Private Sub Workbook_Deactivate()
Application.CutCopyMode = True
Application.CommandBars("cell").Controls("Paste").Visible = True
Application.CommandBars("cell").Controls("Paste Special...").Visible = True
Application.OnKey "^v"
End Sub
 
Last edited by a moderator:
Upvote 0
First, please use code tags when posting code. :)

Second, remove this line as it's pointless:

Code:
Application.CutCopyMode = True

Third, did you move or copy the code? You need to keep the original code if you want it to work when switching sheets within the workbook as well. (I'm assuming the original code did work)
 
Upvote 0
First, please use code tags when posting code. :)

Second, remove this line as it's pointless:

Code:
Application.CutCopyMode = True

Third, did you move or copy the code? You need to keep the original code if you want it to work when switching sheets within the workbook as well. (I'm assuming the original code did work)

Hi Rory,

Thank you, I have removed that line and apologies for the code. I have kept this in the Workbook and copied the code in to the Worksheet with Worksheet_Active rather than the Workbook_Active but sadly this does not appear to be working. I am not sure what I am doing wrong :eek:
 
Upvote 0
Did the code work originally?
 
Upvote 0
Did the code work originally?

Morning Rory,

It hasn't properly worked at all and I'm just not too sure what I'm doing wrong. The Paste & Paste Special... are hidden, but the Paste Clipboard isn't. Is it possible just to disable right click for ALL the sheets of this workbook and disable the Paste Clipboard, as this would solve my issue?

This is what I have in the Worksheet of Sheet1

Code:
Private Sub Worksheet_Activate()
Application.CommandBars("cell").Controls("Paste").Visible = False
Application.CommandBars("cell").Controls("Paste Special...").Visible = False
Application.CutCopyMode = False
Application.OnKey "^v", ""
End Sub


Private Sub Worksheet_Deactivate()
Application.CommandBars("cell").Controls("Paste").Visible = True
Application.CommandBars("cell").Controls("Paste Special...").Visible = True
Application.OnKey "^v"
End Sub

This is what I have in the ThisWorkbook tab (not in a Module)

Code:
Private Sub Workbook_Activate()
Application.CommandBars("cell").Controls("Paste").Visible = False
Application.CommandBars("cell").Controls("Paste Special...").Visible = False
Application.CutCopyMode = False
Application.OnKey "^v", ""
End Sub


Private Sub Workbook_Deactivate()
Application.CommandBars("cell").Controls("Paste").Visible = True
Application.CommandBars("cell").Controls("Paste Special...").Visible = True
Application.OnKey "^v"
End Sub

Thank you.
 
Upvote 0
What do you mean specifically by the Paste Clipboard? If you mean the Clipboard task pane, I'm not sure you can disable that.

Incidentally, if you have Excel 2010 or later, you can disable those right-click items using the CustomUI part of the workbook and no code at all.
 
Upvote 0
What do you mean specifically by the Paste Clipboard? If you mean the Clipboard task pane, I'm not sure you can disable that.

Incidentally, if you have Excel 2010 or later, you can disable those right-click items using the CustomUI part of the workbook and no code at all.


Hi Rory,

Thank you for that, yes I see the options to disable Paste etc, however it does not disable the Ctrl+V paste option. Would the following code work for the workbook?

Code:
Private Sub Workbook_Activate()
Application.OnKey "^v", ""
End Sub


Private Sub Workbook_Deactivate()
Application.OnKey "^v"
End Sub

Many thanks
 
Upvote 0
Yes. :) You could just test...
 
Upvote 0

Forum statistics

Threads
1,215,020
Messages
6,122,712
Members
449,093
Latest member
Mnur

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