Search code examples
excelvbamacos

commandbars("list range popup") in MacOS Excel


I add button on cell rightclick using below code.

When I have some content in the sheet as table its not working in those cells. Its working in rest of the cells in the sheet.

Set TableCellMenu = Application.CommandBars("cell").Controls.Add(Temporary:=True, before:=1, Type:=msoControlButton)   
With TableCellMenu
    .Caption = "MyButton"            
    .FaceId = 755                                       
    .OnAction = "Writeback"         
End With

I got to know that there are two types of context menus. I am looking for "List range popup".

Set TableCellMenu = Application.CommandBars("list range popup").Controls.Add(Temporary:=True, before:=1, Type:=msoControlButton)   
With TableCellMenu
 .Caption = "MyButton"            
 .FaceId = 755                                       
 .OnAction = "Writeback"         
End With

I tried changing the string to camel case.


Solution

  • The Excel context menu is a popup menu that becomes visible when you right-click on a cell, chart, or any other object within your worksheet. It is important to locate the correct menu if you aim to customize the controls on the context menu.

    list range popup is the context menu for a table (This name can be confusing, Insert > Table). Importing a CSV file using QueryTables will create a query table. You could customize its context menu as below.

    Set TableCellMenu = Application.CommandBars("query").Controls. _
            Add(Temporary:=True, before:=1, Type:=msoControlButton)
    With TableCellMenu
        .Caption = "MyButton"
        .FaceId = 755
        .OnAction = "Writeback"
    End With