Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Sub addMenu()
Dim cmdbar As CommandBar
Dim toolsMenu As CommandBarControl
Dim myMenu As CommandBarPopup
Dim subMenu As CommandBarControl
[green]' Point to the Worksheet Menu Bar[/green]
Set cmdbar = Application.CommandBars("Worksheet Menu Bar")
[green]' Point to the Tools menu on the menu bar[/green]
Set toolsMenu = cmdbar.Controls("Tools")
[green]' Create My Menu[/green]
Set myMenu = toolsMenu.Controls.Add(Type:=msoControlPopup)
[green]' Create the sub Menu(s)[/green]
Set subMenu = myMenu.Controls.Add
With myMenu
.Caption = "My Menu"
.BeginGroup = True
With subMenu
.Caption = "sub Menu"
.BeginGroup = True
.OnAction = "'" & ThisWorkbook.name & "'!myMacro" [green]' Assign Macro to Menu Item[/green]
End With
End With
End Sub
Private Sub myMacro()
MsgBox ("My Sub Menu Command")
End Sub
[green] ' How to remove the menu item [/green]
Sub removeMenu()
On Error Resume Next
Dim cmdbar As CommandBar
Dim CmdBarMenu As CommandBarControl
Set cmdbar = Application.CommandBars("Worksheet Menu Bar")
Set CmdBarMenu = cmdbar.Controls("Tools")
CmdBarMenu.Controls("My Menu").Delete
End Sub