在 vb.net 中的 Excel 单元格上下文菜单中添加子菜单

Add sub-menu to cell context menu in Excel in vb.net

我在 vb.net 中为 excel 创建了一个插件 我想向单元格上下文菜单添加一些快捷方式。我设法在这里找到一个解决方案来添加按钮 https://social.msdn.microsoft.com/Forums/en-US/ae7a6cdd-db2c-4edd-a62a-ac35a466ae5c/how-to-assign-a-method-to-a-commandbarbutton-in-a-cell-contextmenu-in-an-vsto-application-addin-for?forum=vsto

但我无法添加子菜单并将这些按钮放入其中

这是我的实际代码 我设法将子菜单和按钮分开,但没有将按钮放入子菜单

Private WithEvents buttonVL03N As CommandBarButton
    Private WithEvents buttonIW53 As CommandBarButton
    Private Sub ThisAddIn_Startup() Handles Me.Startup
        Dim rcCellContextMenu As CommandBar = Globals.ThisAddIn.Application.CommandBars("Cell")
        Dim myMenu As CommandBarPopup

        myMenu = TryCast(rcCellContextMenu.Controls.Add(MsoControlType.msoControlPopup, Before:=3), CommandBarPopup)
        myMenu.Caption = "SAP Transactions"
        myMenu.Tag = "SAP shortcuts "
        buttonVL03N = TryCast(rcCellContextMenu.Controls.Add(MsoControlType.msoControlButton, Id:=1, Before:=3, Temporary:=True), CommandBarButton)
        buttonIW53 = TryCast(rcCellContextMenu.Controls.Add(MsoControlType.msoControlButton, Id:=1, Before:=4, Temporary:=True), CommandBarButton)

        If buttonVL03N IsNot Nothing Then
            buttonVL03N.Caption = "VL03N"
            buttonVL03N.BeginGroup = False
            buttonVL03N.Tag = "Run VL03N"
            buttonVL03N.Enabled = True
        End If

        If buttonIW53 IsNot Nothing Then
            With buttonIW53
                .Caption = "IW53"
                .BeginGroup = False
                .Tag = "Run IW53"
                .Enabled = True
            End With
        End If
    End Sub

我尝试了以下方法

buttonVL03N = TryCast(myMenu.Controls.Add(MsoControlType.msoControlButton, Id:=1, Before:=3, Temporary:=True), CommandBarButton)

但显然这不是那么简单

    buttonVL03N = TryCast(myMenu.CommandBar.Controls.Add(MsoControlType.msoControlButton, Id:=1, Temporary:=True), CommandBarButton)
    buttonIW53 = TryCast(myMenu.CommandBar.Controls.Add(MsoControlType.msoControlButton, Id:=1, Temporary:=True), CommandBarButton)

工作正常