Multiple Blank Context Menus Appearing

BrianExcel

Well-known Member
Joined
Apr 21, 2010
Messages
975
I am using the following code to populate a custom context menu in my workbook:

Code:
Sub AddToCellMenu()Dim ContextMenu As CommandBar
Dim MySubMenu As CommandBarControl, ctrl As CommandBarControl


'Set ContextMenu to the Cell menu
    Set ContextMenu = Application.CommandBars("Cell")
    
    For Each ctrl In ContextMenu.Controls
        If ctrl.Tag = "My_Cell_Control_Tag" Then
            ctrl.Delete
        End If
    Next ctrl


'Set ContextMenu to the Cell menu
    Set ContextMenu = Application.CommandBars("Cell")


'Add custom menu with two sub-buttons
    Set MySubMenu = ContextMenu.Controls.Add(Type:=msoControlPopup, before:=4)


    With MySubMenu
    .Caption = "Raw Data Access"
    .Tag = "My_Cell_Control_Tag"
        With .Controls.Add(Type:=msoControlButton)
            .OnAction = "'" & ThisWorkbook.Name & "'!" & "Hide_Unhide_Venue_Info"
            .FaceId = 4165
            .Caption = "Hide / Unhide Venue Info"
        End With
        With .Controls.Add(Type:=msoControlButton)
            .OnAction = "'" & ThisWorkbook.Name & "'!" & "Hide_Unhide_Expense_Account_Guide"
            .FaceId = 4165
            .Caption = "Hide / Unhide Expense Account Guide"
        End With
    End With


End Sub

I went ahead and integrated the "Delete from Cell Menu" code into the same module just to make it a bit easier.

My problem is that in addition to the menu I want, which is appearing correctly, currently as the fourth option down, the context menu is also giving me 3 additional blank options before it. Each one is similar to a drop-down, and has no code attached to it, but I can't figure out how to remove them.

See the attached picture for the menus I am referring to...

Mm6jRAJO8Cp3CmoWiBcSlBUuchbplfF2F6XFziv3MVU


Anyone have any ideas how I can remove those three menus?
 
Last edited:

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Got it - adding a single line at the top did the job.

Code:
Application.CommandBars("Cell").Reset
 
Upvote 0

Forum statistics

Threads
1,215,692
Messages
6,126,230
Members
449,303
Latest member
grantrob

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top