+ Reply to Thread
Results 1 to 6 of 6

How to "pimp" (with FaceIds and shortcuts combo) a custom menu?

  1. #1
    Registered User
    Join Date
    07-14-2006
    Location
    Netherlands
    MS-Off Ver
    2000, 2003, and 2007
    Posts
    32

    How to "pimp" (with FaceIds and shortcuts combo) a custom menu?

    I've got the following code for a custom menu and it's working fine BUT how can I add FaceIds to the menu items? Is it also possible to show the custom shortcuts like they are showed in the default menu's (e.g. Ctrl+S for Save in menu File)?


    PHP Code: 
    '
    Macro found www.romanpress.com/Articles/Menus_R/Menus.htm
    ' Made some minor adjustments only
    '
    Private Sub AddMenu()
        
    Dim cbpop As CommandBarControl
        Dim cbctl 
    As CommandBarControl
        Dim cbsub 
    As CommandBarControl
        Dim cbpos 
    As Integer

        On Error Resume Next
        Application
    .CommandBars("Worksheet Menu Bar").Controls("Custom Menu").Delete
        On Error 
    GoTo 0

        
    ' Create a popup control on the main menu bar
        cbpos = Application.CommandBars("Worksheet Menu Bar").Controls("Help").Index

        Set cbpop = Application.CommandBars("Worksheet Menu Bar"). _
            Controls.Add(Type:=msoControlPopup, Before:=cbpos)
            cbpop.Caption = mname
            cbpop.Visible = True

        ' 
    Add menu item
        Set cbctl 
    cbpop.Controls.Add(Type:=msoControlButton)
            
    cbctl.Visible True
            cbctl
    .Style msoButtonCaption
            cbctl
    .Caption "&Update rapport"
            
    cbctl.OnAction "UpdateRapport"

        ' Add menu item
        Set cbctl = cbpop.Controls.Add(Type:=msoControlButton)
            cbctl.Visible = True
            cbctl.Style = msoButtonCaption
            cbctl.Caption = "&Print all sheets"
            cbctl.OnAction = "PrintAllSheets"

        ' 
    Add a popup for a submenu
        Set cbsub 
    cbpop.Controls.Add(Type:=msoControlPopup)
            
    cbsub.Visible True
            cbsub
    .Caption "Rapport op&slaan als..."
            ' Add submenu item
            Set cbctl = cbsub.Controls.Add(Type:=msoControlButton)
                cbctl.Visible = True
                cbctl.Style = msoButtonCaption
                cbctl.Caption = "Save As (Preformatted)"
                cbctl.OnAction = "SaveAs"
            ' 
    Add submenu item
            Set cbctl 
    cbsub.Controls.Add(Type:=msoControlButton)
                
    cbctl.Visible True
                cbctl
    .Style msoButtonCaption
                cbctl
    .Caption "Save Copy As (Preformatted)"
                
    cbctl.OnAction "SaveCopyAs"
    End Sub 
    Life's a canvas, you fill the picture!

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    Not a expert ob VBA but think it's

    .FaceId = then the number

    The link will help with what number has what faceid

    http://www.j-walk.com/ss/excel/tips/tip67.htm

    Not sure how to underline the text to display a shortcut

    VBA Noob

  3. #3
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi Again,

    If you add a macro button. Then Change it's name. Put a "&" before the letter you want underlined.

    VBA Noob

  4. #4
    Norman Jones
    Guest

    Re: How to pimp my custom menu (want to display FaceIds and shortcuts combo)?

    Hi s80NL,

    Try changing your first control code to something like:

    ' Add menu item
    Set cbctl = cbpop.Controls.Add(Type:=msoControlButton)
    With cbctl
    .Visible = True
    .Style = msoButtonIconAndCaption
    .Caption = "&Update rapport Shift-Ctrl+P"
    .OnAction = "UpdateRapport"
    .FaceId = 2817
    End With


    ---
    Regards,
    Norman



    "s80NL" <[email protected]> wrote in
    message news:[email protected]...
    >
    > I've got the following code for a custom menu and it's working fine BUT
    > how can I add FaceIds to the menu items? Is it also possible to show
    > the custom shortcuts like they are showed in the default menu's (e.g.
    > Ctrl+S for _S_ave in menu _F_ile?
    >
    >
    >
    > PHP code:
    > --------------------
    > '
    > ' Macro found @ www.romanpress.com/Articles/Menus_R/Menus.htm
    > ' Made some minor adjustments only
    > '
    > Private Sub AddMenu()
    > Dim cbpop As CommandBarControl
    > Dim cbctl As CommandBarControl
    > Dim cbsub As CommandBarControl
    > Dim cbpos As Integer
    >
    > On Error Resume Next
    > Application.CommandBars("Worksheet Menu Bar").Controls("Custom
    > Menu").Delete
    > On Error GoTo 0
    >
    > ' Create a popup control on the main menu bar
    > cbpos = Application.CommandBars("Worksheet Menu
    > Bar").Controls("Help").Index
    >
    > Set cbpop = Application.CommandBars("Worksheet Menu Bar"). _
    > Controls.Add(Type:=msoControlPopup, Before:=cbpos)
    > cbpop.Caption = mname
    > cbpop.Visible = True
    >
    > ' Add menu item
    > Set cbctl = cbpop.Controls.Add(Type:=msoControlButton)
    > cbctl.Visible = True
    > cbctl.Style = msoButtonCaption
    > cbctl.Caption = "&Update rapport"
    > cbctl.OnAction = "UpdateRapport"
    >
    > ' Add menu item
    > Set cbctl = cbpop.Controls.Add(Type:=msoControlButton)
    > cbctl.Visible = True
    > cbctl.Style = msoButtonCaption
    > cbctl.Caption = "&Print all sheets"
    > cbctl.OnAction = "PrintAllSheets"
    >
    > ' Add a popup for a submenu
    > Set cbsub = cbpop.Controls.Add(Type:=msoControlPopup)
    > cbsub.Visible = True
    > cbsub.Caption = "Rapport op&slaan als..."
    > ' Add submenu item
    > Set cbctl = cbsub.Controls.Add(Type:=msoControlButton)
    > cbctl.Visible = True
    > cbctl.Style = msoButtonCaption
    > cbctl.Caption = "Save As (Preformatted)"
    > cbctl.OnAction = "SaveAs"
    > ' Add submenu item
    > Set cbctl = cbsub.Controls.Add(Type:=msoControlButton)
    > cbctl.Visible = True
    > cbctl.Style = msoButtonCaption
    > cbctl.Caption = "Save Copy As (Preformatted)"
    > cbctl.OnAction = "SaveCopyAs"
    > End Sub
    > --------------------
    >
    >
    > --
    > s80NL
    >
    >
    > ------------------------------------------------------------------------
    > s80NL's Profile:
    > http://www.excelforum.com/member.php...o&userid=36374
    > View this thread: http://www.excelforum.com/showthread...hreadid=561781
    >




  5. #5
    Dave Peterson
    Guest

    Re: How to pimp my custom menu (want to display FaceIds and shortcutscombo)?

    How about...

    Set cbctl = cbpop.Controls.Add(Type:=msoControlButton)
    With cbctl
    .Visible = True
    .Style = msoButtonIconAndCaption
    .Caption = "&Update rapport"
    .ShortcutText = "Ctrl-M"
    .OnAction = "UpdateRapport"
    .FaceId = 2817
    End With

    Application.MacroOptions Macro:="UpdateRapport", _
    HasShortcutKey:=True, ShortcutKey:="M"

    s80NL wrote:
    >
    > I've got the following code for a custom menu and it's working fine BUT
    > how can I add FaceIds to the menu items? Is it also possible to show
    > the custom shortcuts like they are showed in the default menu's (e.g.
    > Ctrl+S for _S_ave in menu _F_ile?
    >
    > PHP code:
    > --------------------
    > '
    > ' Macro found @ www.romanpress.com/Articles/Menus_R/Menus.htm
    > ' Made some minor adjustments only
    > '
    > Private Sub AddMenu()
    > Dim cbpop As CommandBarControl
    > Dim cbctl As CommandBarControl
    > Dim cbsub As CommandBarControl
    > Dim cbpos As Integer
    >
    > On Error Resume Next
    > Application.CommandBars("Worksheet Menu Bar").Controls("Custom Menu").Delete
    > On Error GoTo 0
    >
    > ' Create a popup control on the main menu bar
    > cbpos = Application.CommandBars("Worksheet Menu Bar").Controls("Help").Index
    >
    > Set cbpop = Application.CommandBars("Worksheet Menu Bar"). _
    > Controls.Add(Type:=msoControlPopup, Before:=cbpos)
    > cbpop.Caption = mname
    > cbpop.Visible = True
    >
    > ' Add menu item
    > Set cbctl = cbpop.Controls.Add(Type:=msoControlButton)
    > cbctl.Visible = True
    > cbctl.Style = msoButtonCaption
    > cbctl.Caption = "&Update rapport"
    > cbctl.OnAction = "UpdateRapport"
    >
    > ' Add menu item
    > Set cbctl = cbpop.Controls.Add(Type:=msoControlButton)
    > cbctl.Visible = True
    > cbctl.Style = msoButtonCaption
    > cbctl.Caption = "&Print all sheets"
    > cbctl.OnAction = "PrintAllSheets"
    >
    > ' Add a popup for a submenu
    > Set cbsub = cbpop.Controls.Add(Type:=msoControlPopup)
    > cbsub.Visible = True
    > cbsub.Caption = "Rapport op&slaan als..."
    > ' Add submenu item
    > Set cbctl = cbsub.Controls.Add(Type:=msoControlButton)
    > cbctl.Visible = True
    > cbctl.Style = msoButtonCaption
    > cbctl.Caption = "Save As (Preformatted)"
    > cbctl.OnAction = "SaveAs"
    > ' Add submenu item
    > Set cbctl = cbsub.Controls.Add(Type:=msoControlButton)
    > cbctl.Visible = True
    > cbctl.Style = msoButtonCaption
    > cbctl.Caption = "Save Copy As (Preformatted)"
    > cbctl.OnAction = "SaveCopyAs"
    > End Sub
    > --------------------
    >
    > --
    > s80NL
    >
    > ------------------------------------------------------------------------
    > s80NL's Profile: http://www.excelforum.com/member.php...o&userid=36374
    > View this thread: http://www.excelforum.com/showthread...hreadid=561781


    --

    Dave Peterson

  6. #6
    Registered User
    Join Date
    07-14-2006
    Location
    Netherlands
    MS-Off Ver
    2000, 2003, and 2007
    Posts
    32
    Thanks to all of you for replying. I got it working with the WITH method

+ 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