PDA

View Full Version : How do I create a dropdown menu in an add-in menu?



boy_plunder
08-26-2009, 01:46 AM
I have pretty much completed a PowerPoint 2003 add-in and menu that lists 16 buttons. It occurred to me that the toolbar is actually quite long, and I have been trying to put all of the buttons in a dropdown menu, but can't seem to figure out how.

The add-in is in auto_open and there is an 'About this menu' button that displays a message form, followed by 15 buttons. All of this works perfectly, but I'd like to try the 15 buttons in a menu to make a neater toolbar generally.

Could anyone help me with this?

boy_plunder
08-26-2009, 05:25 AM
I have just noticed another post very recently that creates a menu and items, and maybe I can review that and find the solution.

If anyone has an example of a toolbar with a dropdown menu on it, please let me know.

John Wilson
08-26-2009, 07:20 AM
You should find the other post does what you need. To make more than two menu items just repeat the "add another" code.

If you have a lot of grouped items you might want to make a pop up menu

Try this to see what I mean:

Public Const TOOLBARNAME As String = "mymenu"
Sub Auto_Open()

Dim myMainMenuBar As CommandBar
Dim myCustomMenu As CommandBarControl
Dim myTempMenu As CommandBarControl

'Creates multi pop up menus

'turn off error handling as no menu will throw error
On Error Resume Next
'remove any old menus
Application.CommandBars.ActiveMenuBar.Controls(TOOLBARNAME).Delete
On Error GoTo errorhandler
'new menu
Set myMainMenuBar = Application.CommandBars.ActiveMenuBar


Set myCustomMenu = myMainMenuBar.Controls.Add(Type:=msoControlPopup, _
before:=4)
myCustomMenu.Caption = TOOLBARNAME
'first pop up
Set myTempMenu = myCustomMenu.Controls.Add(Type:=msoControlPopup)
myTempMenu.Caption = "Do this..."

With myTempMenu.Controls.Add(Type:=msoControlButton)
.Caption = "Yes this 1"
.TooltipText = "Does this 1"
.OnAction = "macro1name" 'name of macro

End With

With myTempMenu.Controls.Add(Type:=msoControlButton)
.Caption = "Yes this 2"
.TooltipText = "Does this 2"
.OnAction = "macro2name" 'name of macro

End With

'second pop up

Set myTempMenu = myCustomMenu.Controls.Add(Type:=msoControlPopup)
myTempMenu.Caption = " Or Do this..."

With myTempMenu.Controls.Add(Type:=msoControlButton)
.Caption = "Or this 1"
.TooltipText = "Or this 1"
.OnAction = "macro3name" 'name of macro

End With

With myTempMenu.Controls.Add(Type:=msoControlButton)
.Caption = "Or this 2"
.TooltipText = "Or this 2"
.OnAction = "macro4name" 'name of macro

End With

Exit Sub

errorhandler:
MsgBox "Sorry there's been an error!" & vbCrLf & Err.Description
End Sub

boy_plunder
08-26-2009, 08:33 AM
I would like to do a menu, which is a little neater in my view, but I'm not making all the decisions on this.

Instead, I have been asked to take all of the like-minded functions and group them in a drop-down list on the floating custom toolbar that the add-in creates. I can't find the right controls to doing this, but I suspect it's just me being a bit green. I've not programmed a toolbar before this.

John Wilson
08-26-2009, 11:33 PM
You are moving into a different level of programming to do this

To add a combo box
Set MyDropDown = Application.CommandBars("YOUR_TOOLBAR_NAME").Controls.add(Type:=msoControlComboBox)
To set a reference something like
Dim octrl As CommandBarComboBox
Set octrl = CommandBars("YOUR_TOOLBAR_NAME").FindControl(Type:=msoControlComboBox)

Then you will have to write code to populate it and check for changes. I wouldn't go there (well I would, but maybe you should convince them to use a menu)
Maybe someone else knows an easier way