Consulting

Results 1 to 6 of 6

Thread: serious problem re: cut copy and paste

  1. #1
    VBAX Regular
    Joined
    Jan 2007
    Posts
    42
    Location

    serious problem re: cut copy and paste

    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


    [VBA]
    '*** 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
    [/VBA]

  2. #2
    VBAX Contributor Ivan F Moala's Avatar
    Joined
    May 2004
    Location
    Auckland New Zealand
    Posts
    185
    Location
    you need to re enable the controls

    eg ToggleCutCopyAndPaste(True)
    Kind Regards,
    Ivan F Moala From the City of Sails

  3. #3
    VBAX Regular
    Joined
    Jan 2007
    Posts
    42
    Location

    ??

    Hi,.. how do you re-enable the controls... sorry for the silly question.. I tried but dont know how to do this

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Just a quick question. Is the following part of the code in the thisworkbook module or in a standard module:
    [VBA]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 [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    VBAX Contributor moa's Avatar
    Joined
    Nov 2006
    Posts
    177
    Location
    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.
    [vba]Sub fixIt()
    Call ToggleCutCopyAndPaste(True)
    End Sub
    [/vba]
    Glen

  6. #6
    VBAX Contributor moa's Avatar
    Joined
    Nov 2006
    Posts
    177
    Location
    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.)
    Glen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •