+ Reply to Thread
Results 1 to 2 of 2

How to Add a pop up menus with multiple menus levels

Hybrid View

elbertvillarreal How to Add a pop up menus... 04-19-2012, 03:21 PM
Chippy Re: How to Add a pop up menus... 04-23-2012, 12:36 PM
  1. #1
    Registered User
    Join Date
    07-01-2010
    Location
    Costa Rica
    MS-Off Ver
    Excel 2007
    Posts
    5

    How to Add a pop up menus with multiple menus levels

    Well as the title says, what i need is to make a pop menu in a sheet and I found a some solution (shown at the bottom) but I need to at least 4 level menus (sorry for my terrible english), and if its posible an action on all of the menus of eache level, just like in the code at the bottom, but with 4 or 5 levels. Thans in advance for your help.





    Option Explicit
    
    Public Const Mname As String = "MyPopUpMenu"
    
    Sub DeletePopUpMenu()
        'Delete PopUp menu if it exist
        On Error Resume Next
        Application.CommandBars(Mname).Delete
        On Error GoTo 0
    End Sub
    
    Sub CreateDisplayPopUpMenu()
        'Delete PopUp menu if it exist
        Call DeletePopUpMenu
    
        'Create the PopUpmenu
        Call Custom_PopUpMenu_1
    
        'Show the PopUp menu
        On Error Resume Next
        Application.CommandBars(Mname).ShowPopup
        On Error GoTo 0
    End Sub
    
    
    Sub Custom_PopUpMenu_1()
        Dim MenuItem As CommandBarPopup
        'Add PopUp menu
        With Application.CommandBars.Add(Name:=Mname, Position:=msoBarPopup, _
                                         MenuBar:=False, Temporary:=True)
    
            'First add two buttons
            With .Controls.Add(Type:=msoControlButton)
                .Caption = "Button 1"
                .FaceId = 71
                .OnAction = "'" & ThisWorkbook.Name & "'!" & "TestMacro"
            End With
    
            With .Controls.Add(Type:=msoControlButton)
                .Caption = "Button 2"
                .FaceId = 72
                .OnAction = "'" & ThisWorkbook.Name & "'!" & "TestMacro"
            End With
    
            'Second Add menu with two buttons
            Set MenuItem = .Controls.Add(Type:=msoControlPopup)
            With MenuItem
                .Caption = "My Special Menu"
    
                With .Controls.Add(Type:=msoControlButton)
                    .Caption = "Button 1 in menu"
                    .FaceId = 71
                    .OnAction = "'" & ThisWorkbook.Name & "'!" & "TestMacro"
                End With
    
                With .Controls.Add(Type:=msoControlButton)
                    .Caption = "Button 2 in menu"
                    .FaceId = 72
                    .OnAction = "'" & ThisWorkbook.Name & "'!" & "TestMacro"
                End With
            End With
    
            'Third add one button
            With .Controls.Add(Type:=msoControlButton)
                .Caption = "Button 3"
                .FaceId = 73
                .OnAction = "'" & ThisWorkbook.Name & "'!" & "TestMacro"
            End With
    
        End With
    End Sub
    
    
    Sub TestMacro()
        MsgBox "Hi There, greetings from the Netherlands"
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: How to Add a pop up menus with multiple menus levels

    The code shows how to add 2 levels of menus, so just repeat the technique for the 3rd, 4th and 5th levels. Add each 1st level button (msoControlButton) or popup (msoControlPopup) to the CommandBar. Add each 2nd level button/popup to a 1st level popup. Add each 3rd level button/popup to a 2nd level popup, etc.
    Post responsibly. Search for excelforum.com

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1