I made an add-in for excel in vb.net I want to add some shortcuts to the cell context menu. I manage to find a solution here to add button 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
But I can't manage to add a submenu and put these buttons inside
Here is my actual code I manage to have the submenu and button separated, but not the buttons into the sub menu
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
and I tried the following
buttonVL03N = TryCast(myMenu.Controls.Add(MsoControlType.msoControlButton, Id:=1, Before:=3, Temporary:=True), CommandBarButton)
but obviously this is not as simple
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)
is working fine