Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Nov 2002
    Posts
    387
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Not sure how to create menus (Word 2000/SR1)

    I am trying to create a menu with sub menus on a word doc via VBA code. I am basing it on Excel code that creates menus but it doesn't work, or at least the intellisense isn't working. Here is code I am using:


    Dim ExistingMenu As CommandBar
    Dim ELGIMenuPosition As Long

    Dim cbrCmdMenu As CommandBarControl ' ELGI menu

    Const menuname = "ELGI_Menu Items"


    Set ExistingMenu = Application.CommandBars("menu Bar")

    ELGIMenuPosition = ExistingMenu.Controls("Help").Index

    Set cbrCmdMenu = ExistingMenu.Controls.Add(Type:=msoControlPopup, _
    Before:=ELGIMenuPosition)


    According to Wrox book "Excel 2002 VBA", page 264 I would create the addition menus using:


    With cbrCmdMenu
    .Caption = "ELGI Menu"
    With .Controls.Add(Type:=msoControlButton)
    .Caption = "bah bah"
    .OnAction = " bah Bah too"

    etc.

    I don't care for the With syntax so I tried

    cbrCmdMenu .Caption = "ELGI menu" ' Which works

    But when I try to do the Add I do not see an controls method such as cbrCmdMenu.Controls, so that I can do the adding of the other menu items. What am I missing here?

    cbrCmdMenu .

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Not sure how to create menus (Word 2000/SR1)

    Jim,

    In spite of the Intellisense not working, have you tried going ahead and adding the controls code and seeing what happens?
    The intellisense doesn't work reliably for all the members of commandbars controls.

    Gary

  3. #3
    3 Star Lounger
    Join Date
    Nov 2002
    Posts
    387
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Not sure how to create menus (Word 2000/SR1)

    Yep it errors out as soon as I hit return.

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

    Re: Not sure how to create menus (Word 2000/SR1)

    If you don't want to use With, you must use a variable of type CommandBarControl, otherwise you have no way to refer to the control you create.

    ' After you have created cbrCmdMenu:
    Dim cbrCtl As CommandBarControl
    Set cbrCtl = cbrCmdMenu.Controls.Add(Type:=msoControlButton)
    cbrCtl.Caption = "MyCaption"
    cbrCtl.OnAction = "MyAction"

Posting Permissions

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