Results 1 to 4 of 4

Multiple menus

Threaded View

  1. #1
    Registered User
    Join Date
    11-12-2009
    Location
    surrey
    MS-Off Ver
    Excel 2003
    Posts
    22

    Multiple menus

    I have this code which adds one menu at the top of the worksheet and I want to add more. My current sheet has a large number of scripts liatsed under it for different purposes and I'd like to divide it into different menus.

    many thanks
    john

    Const TopMenuName = "Virgin &Money Giving"
       
    Public Sub Workbook_Open()
    
        Dim iHelpMenu As Integer
        Dim cmbBar As CommandBar
        Dim cmbControl As CommandBarControl
         
        On Error Resume Next
        
        Set cmbBar = Application.CommandBars("Worksheet Menu Bar")
        
        iHelpMenu = cmbBar.Controls("Help").Index
        
       ' delete if already there
        For Each cmbControl In cmbBar.Controls
    
            If cmbControl.Caption = TopMenuName Or TopMenuName2 Then
                cmbBar.Controls(TopMenuName).Delete
            End If
    
        Next
        
        Set cmbControl = cmbBar.Controls.Add(Type:=msoControlPopup, Before:=iHelpMenu, temporary:=True)  'adds a menu item to the Menu Bar
        With cmbControl
            .Caption = TopMenuName 'names the menu item
            With .Controls.Add(Type:=msoControlButton) 'adds a dropdown button to the menu item
            .Caption = "Process Payment File" 'adds a description to the menu item
            .OnAction = "VirginMoney" 'runs the specified macro
            .FaceId = 37 'assigns an icon to the dropdown
            End With
         
    End With
        
        Range("A1").Select
        
    End Sub
    
    Public Sub Workbook_BeforeClose(Cancel As Boolean)
        On Error Resume Next 'in case the menu item has already been deleted
        Application.CommandBars("Worksheet Menu Bar").Controls(TopMenuName).Delete 'delete the menu item
    End Sub
    Last edited by wishmaker; 01-13-2010 at 01:57 PM.

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