Results 1 to 2 of 2

Thread: Disable cut (CTRL x) in Excel

  1. #1

    Disable cut (CTRL x) in Excel



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Is there a simple macro - similar to your "CutCopyPasteDisabled" macro (see below) - for disabling the CUT command only?

    I only need to disable cut (CTRL x) because moving cells messes up my formulas when I do this by accident. Everything else is okay.

    Here's the code written by Ken Puls:



    Code:
    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
    If cBar.Name <> "Clipboard" Then
    Set cBarCtrl = cBar.FindControl(ID:=ctlId, recursive:=True)
    If Not cBarCtrl Is Nothing Then cBarCtrl.Enabled = Enabled
    End If
    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

  2. #2
    Super Moderator p45cal's Avatar
    Join Date
    Dec 2012
    Posts
    1,480
    Articles
    0
    Excel Version
    365
    At its simplest, just disable some lines, and perhaps change the name of the sub:
    Code:
    Sub ToggleCut(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
    Completely untested.

Posting Permissions

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