Question

I used this vba code in the ThisWorkbook module to disable the right click menu in an Excel workbook.

Private Sub Workbook_Activate()
   With Application.CommandBars.FindControl(ID:=847)
      .Visible = False
   End With
End Sub

Private Sub Workbook_Deactivate()
   With Application.CommandBars.FindControl(ID:=847)
      .Visible = True
   End With
End Sub

Works like a charm.
Problem is, I can't access the right click menu on tabs in ANY workbook now. The second part of the code is supposed to turn it back on, I assumed? Yet it doesn't.

Even when I remove the code entirely, no workbook, not even a new one, has a menu when I click right on one of the tabs.

Is there a general vba codesnippet that "resets" excel maybe? Or a general "enable all menus" thing?

REVISION: This code posted here doesn't disable the rightclick menu, it removes the "delete" option from that specific menu.

Was it helpful?

Solution

omg

Application.CommandBars("Ply").Enabled = True

-.-
Started googling different keywords after the last edit and BAM.

OTHER TIPS

Late again as usual, but tackled with the same problem today. Here's the solution to get your right-click functionality back:

Option Explicit
'
Sub tester()
    '
    Dim cBar As CommandBar
    '
    For Each cBar In CommandBars
        Debug.Print cBar.Name
        If (cBar.Type = msoBarTypePopup) Then cBar.Enabled = True
    Next
End Sub

Also note that the below also exist. Some macro from work had them all disabled in my Excel.

Application.CommandBars("Cell").Enabled = True
Application.CommandBars("Row").Enabled = True
Application.CommandBars("Column").Enabled = True
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top