PDA

View Full Version : serious problem re: cut copy and paste



cbs81
04-11-2007, 08:04 PM
I have inserted the following code in and even when I go back and delete this code... even Turn off my computer the cut copy paste feature is permanently disabled in my excel... this is the code i got off this same site...can somebody help me out please how to re-enable this function..

thankyou



'*** In a standard module ***
Option Explicit

Sub ToggleCutCopyAndPaste(Allow As Boolean)
'Activate/deactivate cut, copy, paste and pastespecial menu items
Call EnableMenuItem(21, Allow) ' cut
Call EnableMenuItem(19, Allow) ' copy
Call EnableMenuItem(22, Allow) ' paste
Call EnableMenuItem(755, Allow) ' pastespecial

'Activate/deactivate drag and drop ability
Application.CellDragAndDrop = Allow

'Activate/deactivate cut, copy, paste and pastespecial shortcut keys
With Application
Select Case Allow
Case Is = False
.OnKey "^c", "CutCopyPasteDisabled"
.OnKey "^v", "CutCopyPasteDisabled"
.OnKey "^x", "CutCopyPasteDisabled"
.OnKey "+{DEL}", "CutCopyPasteDisabled"
.OnKey "^{INSERT}", "CutCopyPasteDisabled"
Case Is = True
.OnKey "^c"
.OnKey "^v"
.OnKey "^x"
.OnKey "+{DEL}"
.OnKey "^{INSERT}"
End Select
End With
End Sub

Sub EnableMenuItem(ctlId As Integer, Enabled As Boolean)
'Activate/Deactivate specific menu item
Dim cBar As CommandBar
Dim cBarCtrl As CommandBarControl
For Each cBar In Application.CommandBars
Set cBarCtrl = cBar.FindControl(Id:=ctlId, recursive:=True)
If Not cBarCtrl Is Nothing Then cBarCtrl.Enabled = Enabled
Next
End Sub

Sub CutCopyPasteDisabled()
'Inform user that the functions have been disabled
MsgBox "Sorry! Cutting, copying and pasting have been disabled in this workbook!"
End Sub

'*** In the ThisWorkbook Module ***
Option Explicit

Private Sub Workbook_Activate()
Call ToggleCutCopyAndPaste(False)
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call ToggleCutCopyAndPaste(True)
End Sub

Private Sub Workbook_Deactivate()
Call ToggleCutCopyAndPaste(True)
End Sub

Private Sub Workbook_Open()
Call ToggleCutCopyAndPaste(False)
End Sub

Ivan F Moala
04-11-2007, 08:43 PM
you need to re enable the controls

eg ToggleCutCopyAndPaste(True)

cbs81
04-11-2007, 09:08 PM
Hi,.. how do you re-enable the controls... sorry for the silly question.. I tried but dont know how to do this

lucas
04-11-2007, 09:42 PM
Just a quick question. Is the following part of the code in the thisworkbook module or in a standard module:
Option Explicit

Private Sub Workbook_Activate()
Call ToggleCutCopyAndPaste(False)
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call ToggleCutCopyAndPaste(True)
End Sub

Private Sub Workbook_Deactivate()
Call ToggleCutCopyAndPaste(True)
End Sub

Private Sub Workbook_Open()
Call ToggleCutCopyAndPaste(False)
End Sub

moa
04-12-2007, 01:30 AM
It works fine for me. Not sure what's going on...

If you want to just get back cut, copy etc. create a sub and run it.
Sub fixIt()
Call ToggleCutCopyAndPaste(True)
End Sub

moa
04-12-2007, 01:36 AM
Lucas has a point. You have the comment: '*** In the ThisWorkbook Module *** but if that is just a comment and your event code isn't in that module the code is not being run when the events occur (Open, activate etc.)