Consulting

Results 1 to 5 of 5

Thread: How do I create a dropdown menu in an add-in menu?

  1. #1

    How do I create a dropdown menu in an add-in menu?

    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?

  2. #2
    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.

  3. #3
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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:

    [VBA]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


    [/VBA]
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  4. #4
    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.

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    You are moving into a different level of programming to do this

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

    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
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •