Home > Mobile >  PEBKAC with Excel
PEBKAC with Excel

Time:06-01

I've managed to disable cut in the right-click menu on Excel 2016 using VBA code I've cut and pasted, and now I can't figure out how to undo what I've done.

I'm a nurse with some technical knowledge (enough to get into trouble...), and my leadership team are bringing in an electronic assignment board based on Excel. As part of the training they said that under no circumstances should we use cut to rearrange the assignments, so I decided to see if there was a way to disable the ability to cut completely.

I found several suggestions to achieve this, and copy-pasted the VBA from several websites. During my trial-and-error attempts I tested multiple times with keyboard shortcuts without realising I'd achieved this in the right-click menu. The PEBKAC moment came when I then removed the modules without exporting, then realising I've made an enduring change and now can't figure out how to undo what I've done.

Any suggestions, or do I need to 'fess up to tech support?

Edit: The two that I know I used were: Option Explicit Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _ ByVal Target As Excel.Range)

Select Case Application.CutCopyMode Case Is = False 'do nothing Case Is = xlCopy 'do nothing Case Is = xlCut MsgBox "Please DO NOT Cut and Paste. Use Copy and Paste; then delete the source." Application.CutCopyMode = False 'clear clipboard and cancel cut End Select

End Sub

...and...

http://www.vbaexpress.com/kb/getarticle.php?kb_id=373

I tried editing the second with no discernable result.

Edit 2: JNevill, fixed! Thanks so much, I'll stop trying to be so smart in the future.

CodePudding user response:

Working backwards using code from that link I shared in the comments, likely running the following will get you back where you started (or close to it):

Sub unBreakMyExcel()
    
    Dim cBar As CommandBar 
    Dim cBarCtrl As CommandBarControl 
    For Each cBar In Application.CommandBars 
        If cBar.Name <> "Clipboard" Then 
            'ID 21 is "Cut" 
            Set cBarCtrl = cBar.FindControl(ID:=21, recursive:=True) 
            If Not cBarCtrl Is Nothing Then cBarCtrl.Enabled = True 
        End If 
    Next 
End Sub 

*I haven't tested this myself. The code is pretty old, but I don't think much has changed between the time that post was made and your version of excel.

What this does is go through each commandbar (which should include the right-click drop down menu) and enable the cut feature, if it exists in the command bar.

  • Related