Adding combobox to right-click menu

20 Ton Squirrel

New Member
Joined
Aug 18, 2011
Messages
11
While customizing the right-click menu for cells, I am unable to get a CommandBarComboBox object to show up. Other controls populate fine and no errors are thrown. It is as though the code for adding the combobox is ignored completely.

My code is below, any guidance would be greatly appreciated!

Code:
'===============================================
' THISWORKBOOK

Option Explicit



Private Sub Workbook_SheetBeforeRightClick(ByVal wks As Object, ByVal rng As Range, booCancel As Boolean)
    
    menuShowTEST
    
End Sub
Code:
'===============================================
' MODULE

Option Explicit

Public Const cMENU_TAG As String = "DS"


Private Sub menuInitializeTEST()
  Dim cbcMain As CommandBarControl
  
    Set cbcMain = Application.CommandBars("Cell").Controls.Add(Type:=msoControlPopup, before:=1, temporary:=True)
    
    With cbcMain
        .Tag = cMENU_TAG
        .Caption = "Report &Filters"
        .BeginGroup = True
    End With
    
    With cbcMain.Controls.Add(Type:=msoControlComboBox, temporary:=True)
        .Tag = cMENU_TAG
        .Caption = "Meow"
        .TooltipText = "Why isn't this showing up?"
        .AddItem "element1"
        .AddItem "element2"
        .AddItem "element3"
        .DropDownLines = 3
        .ListIndex = 1
    End With
    
    With cbcMain.Controls.Add(Type:=msoControlButton, temporary:=True)
        .Tag = cMENU_TAG
        .Caption = "Apply"
        .TooltipText = "Apply selected filters to data."
        .OnAction = "menuFilterApply"
        .BeginGroup = True
    End With
    
    With cbcMain.Controls.Add(Type:=msoControlButton, temporary:=True)
        .Tag = cMENU_TAG
        .Caption = "Remove"
        .TooltipText = "Removes filters from data."
        .OnAction = "menuFilterRemove"
        .BeginGroup = False
    End With


End Sub


Public Sub menuShowTEST()

    menuRemoveTEST
    menuInitializeTEST
    

End Sub



Public Sub menuRemoveTEST()
  Dim cbc As CommandBarControl
  
    On Error Resume Next
    
    For Each cbc In Application.CommandBars.FindControls(Tag:=cMENU_TAG)
        cbc.Delete
    Next
       
    On Error GoTo 0
End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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