![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: May 2002
Posts: 206
|
Would like to know if it's possible to write code in a workbook to disable the copy function while veiwing the workbook.
|
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Mar 2002
Location: Sydney/Brisbane , Australia
Posts: 539
|
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! |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: May 2002
Posts: 206
|
Thanks, I'll give it a whirl. (have always wanted to visit Australia)
|
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Mar 2002
Location: Sydney/Brisbane , Australia
Posts: 539
|
Australia = GR8 place, GR8 people.
|
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Mar 2002
Posts: 363
|
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 ] |
|
|
|
|
|
#6 |
|
Board Regular
Join Date: Mar 2002
Location: Sydney/Brisbane , Australia
Posts: 539
|
Ricky..
does that hide the option or does it just disable it? |
|
|
|
|
|
#7 |
|
Board Regular
Join Date: Mar 2002
Posts: 363
|
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 ] |
|
|
|
|
|
#8 |
|
Board Regular
Join Date: Mar 2002
Location: Sydney/Brisbane , Australia
Posts: 539
|
you're right. Its never too late to learn something new
__________________
Colin |
|
|
|
|
|
#9 |
|
MrExcel MVP
Join Date: Feb 2002
Location: San Francisco, California USA
Posts: 10,388
|
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 |
|
|
|
|
|
#10 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
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; Private Sub Workbook_WindowDeactivate(ByVal Wn As Window) Application.CutCopyMode = False End Sub And Also 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 |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|