Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Jun 2004
    Location
    Gtr London, England
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sub Menu on Customized Command Bar (Office XP)

    Can anyone help? I am creating a command bar through VBA and want to use sub menus but am having difficulty with the coding.

    The section of code below, creates a "Templates" button on the menu bar, then creates a "Letter" button on the menu bar - I would like the "Letter" button to appear under "Templates". (In the same way that if you click on "File", you get a list of options available under the button.) I have looked on help and through the internet but cannot seem to find a solution.


    Set ctlTemplates = cbrCommandbar.Controls.Add(msoControlButton, 2)
    With ctlTemplates
    .Caption = "Templates"
    .Style = msoButtonIconAndCaption
    .Visible = True
    .BeginGroup = True
    End With

    Set ctlLetter = cbrCommandbar.Controls.Add(msoControlButton, 3)
    With ctlLetter
    .Caption = "Letter"
    .Style = msoButtonCaption
    .Visible = True
    End With

    Many thanks.
    Jack

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sub Menu on Customized Command Bar (Office XP)

    Like this:

    Set ctlTemplates = cbrCommandbar.Controls.Add(msoControlPopup, 2)
    With ctlTemplates
    .Caption = "Templates"
    .Style = msoButtonIconAndCaption
    .Visible = True
    .BeginGroup = True
    End With

    Set ctlLetter = ctlTemplates.Controls.Add(msoControlButton, 3)
    With ctlLetter
    .Caption = "Letter"
    .Style = msoButtonCaption
    .Visible = True
    End With

    (untested)!
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Sub Menu on Customized Command Bar (Office XP)

    You must create ctlTemplates as a msoControlPopup instead of a msoControlButton, and create ctlLetter by adding to the Controls collection of ctlTemplates:

    Set ctlTemplates = cbrCommandBar.Controls.Add(msoControlPopup)
    With ctlTemplates
    .Caption = "Templates"
    .Visible = True
    .BeginGroup = True
    End With

    Set ctlLetter = ctlTemplates.Controls.Add(msoControlButton)
    With ctlLetter
    .Caption = "Letter"
    .Style = msoButtonCaption
    .Visible = True
    End With

    Note: I removed the line .Style = msoButtonIconAndCaption because that is not valid for a msoControlPopup.

  4. #4
    Star Lounger
    Join Date
    Jun 2004
    Location
    Gtr London, England
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sub Menu on Customized Command Bar (Office XP)

    Thanks Hans (and also Jan Karel)

    Everything is working fabulously well now.

    Regards
    Jack

Posting Permissions

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