VBA to Disable Copy/Paste Entirely

default_name

Board Regular
Joined
May 16, 2018
Messages
170
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
Hey guys!

Is there a way, using VBA, to entirely prevent users from using the copy/cut/paste feature?

I have seen a few posts online that talk about making this possible on protected workbooks.
But is there a way to disable the copy/cut/paste features regardless of whether or not the document is in the protected mode?
In other words...how can I completely disable copying/cutting/pasting in my workbook in all instances, whether it is locked/protected or not?

I have tried using:
VBA Code:
Application.CutCopyMode = False
in the ThisWorkbook vba sheet...but that doesnt seem to do anything.

Thanks in advance!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
I have done this. That code needs to be in the THISWORKBOOK module. Your going to have lock down the VBA. It won't stop the people that know how to bypass macros. I can't seem to prevent copying from other applications and pasting to a cell. It prevents pasting between sheets, workbooks, and cells.

VBA Code:
Private Sub Workbook_Open()
  ClearClipboard
End Sub

Private Sub Workbook_Activate()
  ClearClipboard
End Sub

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
  ClearClipboard
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
  ClearClipboard
End Sub

Private Sub Workbook_WindowActivate(ByVal Wn As Window)
  ClearClipboard
End Sub


Sub ClearClipboard()
  
  Dim Sht As Worksheet
  Set Sht = ActiveSheet
  With Sht
   .Cells(.Cells.Rows.Count, .Cells.Columns.Count).Copy
  End With
  Application.CutCopyMode = False
End Sub
 
Upvote 0
Thanks Jeffrey!
That code works in disabling the copy/paste functions (just as requested)...but it also slows down the entire workbook considerably.
 
Upvote 0
I was just playing around with the code, and this seems to work without slowing down the workbook:

VBA Code:
Private Sub Workbook_Open()
    ClearClipboard
End Sub

Private Sub Workbook_Activate()
  ClearClipboard
End Sub

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
  ClearClipboard
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
  ClearClipboard
End Sub

Private Sub Workbook_WindowActivate(ByVal Wn As Window)
  ClearClipboard
End Sub

Sub ClearClipboard()
  Application.CutCopyMode = False
End Sub

I took out the Dim, Set and With statements in the ClearClipboard sub...it seems to be working as I'd hoped....but perhaps I'm missing something. ?
What was the purpose for the Dim, Set and With statements?

Thanks again!!
 
Upvote 0
This statement doesn't actually kill anything stored in the clipboard from external sources. It will stop a person from copy paste internally to Excel.

Application.CutCopyMode = False
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,858
Members
449,051
Latest member
excelquestion515

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