Disable copy function

dsnbld

Board Regular
Joined
May 7, 2002
Messages
206
Would like to know if it's possible to write code in a workbook to disable the copy function while veiwing the workbook.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
i did this by putting in the auto_open macro a command to hide all toolbars, and then
Application.OnKey "^c", ""
Application.OnKey "^v", ""

so that CTRl C, and CTRL V are both disabled

remember to reenable the CTRL keys with your auto close macro

Application.OnKey "^c"
Application.OnKey "^v"


hope this helps a bit! :)
 
Upvote 0
In addition to the onkey methods mentioned above you need to disable the copy command on the Edit menu and the cell right-click menu by doing the following:

CommandBars(1).Controls("Edit").Controls("Copy").Enabled = False
CommandBars(21).Controls("Copy").Enabled = False

_________________
It's never too late to learn something new.

Ricky
This message was edited by Ricky Morris on 2002-05-08 18:21
 
Upvote 0
It disables it. To delete it try:

CommandBars(1).Controls("Edit").Controls("Copy").Delete
CommandBars(21).Controls("Copy").Delete

But you would need to reset the menubars when you're done. With the disable method you would need to enable them when done by changing true to false

_________________
It's never too late to learn something new.

Ricky
This message was edited by Ricky Morris on 2002-05-08 18:27
 
Upvote 0
Try covering your bases with this in your Workbook module:

Private Sub Workbook_Activate()
With Application
.CutCopyMode = False
.CellDragAndDrop = False
End With
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 file:"
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)
With Application
.OnKey "^c", ""
.CutCopyMode = False
End With
End Sub
Private Sub Workbook_Deactivate()
With Application
.CellDragAndDrop = True
.OnKey "^c"
.CutCopyMode = False
End With
End Sub
 
Upvote 0
Tom is right....you should cover all your bases as the user can still have the Cut
or copy button in another commandbar.
As well as toms you can try this,

Don't forget that the user can still
Cut to another Workbook.

In the Thisworkbook object;

<pre/>
Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
Application.CutCopyMode = False
End Sub
</pre>

And Also

<pre/>
Sub DisableCopy()
EnableControl 19, False ' copy
EnableControl 21, False ' cut
Application.CommandBars("Toolbar List").Enabled = False
Application.OnKey "^C", ""
End Sub

Sub EnableCopy()
EnableControl 19, True ' copy
EnableControl 21, True ' cut
Application.CommandBars("Toolbar List").Enabled = True
Application.OnKey "^C"
End Sub

Sub EnableControl(Id As Integer, Enabled As Boolean)
Dim CB As CommandBar
Dim Ctrl As CommandBarControl

On Error Resume Next
For Each CB In Application.CommandBars
Set Ctrl = CB.FindControl(Id:=Id, recursive:=True)
If Not Ctrl Is Nothing Then Ctrl.Enabled = Enabled
Next
End Sub

</pre>
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,915
Members
448,532
Latest member
9Kimo3

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