Sub BigDelGooner()
Dim cmdbr As CommandBar, cbc As CommandBarControl, cbcNew As CommandBarControl
Dim cbcOpt As CommandBarControl, cbcBtn As CommandBarControl
Set cmdbr = Application.CommandBars("Worksheet Menu Bar")
Set cbc = cmdbr.Controls.Add(Type:=msoControlPopup, temporary:=True)
With cbc
.Caption = "&BigDelGooner"
.Visible = True
.Tag = "BigDelGooner"
.TooltipText = "Example menu for BigDelGooner"
.Move before:=cmdbr.Controls.Count - 1
End With
Set cbcNew = CreateControl(cbc, "Main Menu &1", "", msoControlPopup)
Set cbcOpt = CreateControl(cbcNew, "Sub-menu &1", "This is a sub-menu", msoControlPopup)
Set cbcBtn = CreateControl(cbcOpt, "Button &1", "This is a button on a sub-menu", msoControlButton)
Set cbcBtn = CreateControl(cbcOpt, "Button &2", "This is a button on a sub-menu", msoControlButton)
Set cbcOpt = CreateControl(cbcNew, "Sub-menu &2", "This is a sub-menu", msoControlPopup)
Set cbcBtn = CreateControl(cbcOpt, "Button &1", "This is a button on a sub-menu", msoControlButton)
Set cbcBtn = CreateControl(cbcOpt, "Button &2", "This is a button on a sub-menu", msoControlButton)
Set cbcOpt = CreateControl(cbcNew, "Sub-menu &3", "This is a sub-menu", msoControlPopup)
Set cbcBtn = CreateControl(cbcOpt, "Button &1", "This is a button on a sub-menu", msoControlButton)
Set cbcBtn = CreateControl(cbcOpt, "Button &2", "This is a button on a sub-menu", msoControlButton)
Set cbcNew = CreateControl(cbc, "Main Menu &2", "", msoControlPopup)
Set cbcOpt = CreateControl(cbcNew, "Sub-menu &1", "This is a sub-menu", msoControlPopup)
Set cbcBtn = CreateControl(cbcOpt, "Button &1", "This is a button on a sub-menu", msoControlButton)
Set cbcBtn = CreateControl(cbcOpt, "Button &2", "This is a button on a sub-menu", msoControlButton)
Set cbcOpt = CreateControl(cbcNew, "Sub-menu &2", "This is a sub-menu", msoControlPopup)
Set cbcBtn = CreateControl(cbcOpt, "Button &1", "This is a button on a sub-menu", msoControlButton)
Set cbcBtn = CreateControl(cbcOpt, "Button &2", "This is a button on a sub-menu", msoControlButton)
Set cbcOpt = CreateControl(cbcNew, "Sub-menu &3", "This is a sub-menu", msoControlPopup)
Set cbcBtn = CreateControl(cbcOpt, "Button &1", "This is a button on a sub-menu", msoControlButton)
Set cbcBtn = CreateControl(cbcOpt, "Button &2", "This is a button on a sub-menu", msoControlButton)
End Sub
Function CreateControl(container As Variant, strCap As String, strTip As String, lngType As MsoControlType, Optional tagLine, Optional Macro) As CommandBarControl
Dim ctrl
Set ctrl = container.Controls.Add(lngType)
With ctrl
.Caption = strCap
.TooltipText = strTip
If Not IsMissing(tagLine) Then .Tag = tagLine
If Not IsMissing(Macro) Then .OnAction = Macro
End With
Set CreateControl = ctrl
End Function