Drop Down Menu

lhernandez

Active Member
Joined
May 22, 2006
Messages
282
Can someone help by telling me how to make a drop down menu (like File Edit View... at the top of a window)?
I would like to make a drop down menu and have the macros attached to it.
Anything ideas would help
Thank you
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
OK, I modified my original code to also include a sub-menu to the MyMenu toolbar popup, it is called "Tools" and has two tool items added to it. The code for this starts at Item 6 in the code below. Notice the change in the MSO object name and the reduced code for getting the sub-menu.


Sub myAdd_MyMenu_ToDefaultToolbar()
'Standard module code, like: Module1!
Dim myNewMainMenu, myNewMainMenuItem
'This adds a new item to the Default toolbar at the very top of the page, like: File Edit View...

On Error GoTo myErr
'Delete custom menu if it exists!
Call Remove_MyMenu

'Add a new item to the default toolbar!
With CommandBars("Worksheet Menu Bar")
Set myNewMainMenu = .Controls.Add(Type:=msoControlPopup, temporary:=True)
End With

'Name this new toolbar item!
myNewMainMenu.Caption = "MyMenu"

'Add a sub-menu item to the new menu list!
Set myNewItem1 = myNewMainMenu.CommandBar.Controls.Add(Type:=msoControlButton, ID:=1)

With myNewItem1
.Caption = "Un-Install"
.TooltipText = "Un-install this MyMenu from this toolbar!"
.Style = msoButtonCaption
.OnAction = "Remove_MyMenu" 'Name of macro to run.
End With

'Add a Second sub-menu item to the new menu list!
Set myNewItem2 = myNewMainMenu.CommandBar.Controls.Add(Type:=msoControlButton, ID:=1)

With myNewItem2
.Caption = "Run Test1"
.TooltipText = "Runs the macro for this item!"
.Style = msoButtonCaption
.OnAction = "myTestItem" 'Name of macro to run.
End With

'Add a Third sub-menu item to the new menu list!
Set myNewItem3 = myNewMainMenu.CommandBar.Controls.Add(Type:=msoControlButton, ID:=1)

With myNewItem3
.Caption = "Run Test2"
.TooltipText = "Runs the macro for this item!"
.Style = msoButtonCaption
.OnAction = "myTestItem" 'Name of macro to run.
End With

'Add a Fourth sub-menu item to the new menu list!
Set myNewItem4 = myNewMainMenu.CommandBar.Controls.Add(Type:=msoControlButton, ID:=1)

With myNewItem4
.Caption = "Run Test3"
.TooltipText = "Runs the macro for this item!"
.Style = msoButtonCaption
.OnAction = "myTestItem" 'Name of macro to run.
End With

'Add a Fith sub-menu item to the new menu list!
Set myNewItem5 = myNewMainMenu.CommandBar.Controls.Add(Type:=msoControlButton, ID:=1)

With myNewItem5
.Caption = "Run Test4"
.TooltipText = "Runs the macro for this item!"
.Style = msoButtonCaption
.OnAction = "myTestItem" 'Name of macro to run.
End With

'Add a SubMenu catagory item to the new menu list!
Set myNewSubMen6 = myNewMainMenu.CommandBar.Controls.Add(Type:=msoControlPopup, temporary:=True)

With myNewSubMen6
.Caption = "Tools"
.TooltipText = "Sub-Menu of Options!"
End With

'Add an Item1 to the "Tools" sub-menu!
Set myNewSubItem1 = myNewSubMen6.CommandBar.Controls.Add(Type:=msoControlButton, ID:=1)

With myNewSubItem1
.Caption = "Tool1"
.TooltipText = "Runs the macro for this tool!"
.Style = msoButtonCaption
.OnAction = "myTestItem" 'Name of macro to run.
End With

'Add an Item2 to the "Tools" sub-menu!
Set myNewSubItem2 = myNewSubMen6.CommandBar.Controls.Add(Type:=msoControlButton, ID:=1)

With myNewSubItem2
.Caption = "Tool2"
.TooltipText = "Runs the macro for this tool!"
.Style = msoButtonCaption
.OnAction = "myTestItem" 'Name of macro to run.
End With
Exit Sub

myErr:
MsgBox "An error has occured, did not create menu items. " & Chr(13) & _
"Error number: " & Err.Number & Chr(13) & "Error Description: " & Err.Description, vbExclamation + vbOKOnly, "Error!"
Resume Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,108
Members
452,302
Latest member
TaMere

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top