Results 1 to 6 of 6
  1. #1
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    CommandBars (VBA/Word/2000 SP-3)

    I have been having trouble with a custom menu item that is saved in a workgroup template not appearing on some machines when the workgroup template is attached as an Add-In. In solving this problem I have decided to have the AutoExec module of the template build a CommandBar. I have been unable to figure out how to code a subset of macros such that the complete structure is similar to the following. Any help will be greatly appreciated.

    <pre> CommandBar
    |
    |- Macro1
    |
    |- Macro2
    |
    |- Subset1
    | |
    | |- Macro3
    | |
    | |- Macro4
    | |
    | |- Subset2
    | |
    | |- Macro5
    | |
    | |- Macro6
    |- Macro7
    |
    |- Subset3
    | |
    | |- Macro8
    | |
    | |- Macro9
    |
    |- Macro10</pre>


    TIA
    Regards
    Don

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

    Re: CommandBars (VBA/Word/2000 SP-3)

    You could do something like this <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Dim cbr As CommandBar
    Dim cbb As CommandBarButton
    Dim cbp0 As CommandBarPopup
    Dim cbp1 As CommandBarPopup
    Dim cbp2 As CommandBarPopup
    Set cbr = Application.CommandBars.Add("Commandbar")
    Set cbp0 = cbr.Controls.Add(Type:=msoControlPopup)
    cbp0.Caption = "MyMenu"
    Set cbb = cbp0.Controls.Add(Type:=msoControlButton)
    cbb.Caption = "Macro1"
    cbb.OnAction = "Macro1"
    cbb.Style = msoButtonCaption
    Set cbb = cbp0.Controls.Add(Type:=msoControlButton)
    cbb.Caption = "Macro2"
    cbb.OnAction = "Macro2"
    cbb.Style = msoButtonCaption
    Set cbp1 = cbp0.Controls.Add(Type:=msoControlPopup)
    cbp1.Caption = "Subset1"
    Set cbb = cbp1.Controls.Add(Type:=msoControlButton)
    cbb.Caption = "Macro3"
    cbb.OnAction = "Macro3"
    cbb.Style = msoButtonCaption
    Set cbb = cbp1.Controls.Add(Type:=msoControlButton)
    cbb.Caption = "Macro4"
    cbb.OnAction = "Macro4"
    cbb.Style = msoButtonCaption
    Set cbp2 = cbp1.Controls.Add(Type:=msoControlPopup)
    cbp2.Caption = "Subset2"
    Set cbb = cbp2.Controls.Add(Type:=msoControlButton)
    cbb.Caption = "Macro5"
    cbb.OnAction = "Macro5"
    cbb.Style = msoButtonCaption
    Set cbb = cbp2.Controls.Add(Type:=msoControlButton)
    cbb.Caption = "Macro6"
    cbb.OnAction = "Macro6"
    cbb.Style = msoButtonCaption
    Set cbb = cbp0.Controls.Add(Type:=msoControlButton)
    cbb.Caption = "Macro7"
    cbb.OnAction = "Macro7"
    cbb.Style = msoButtonCaption
    Set cbp1 = cbp0.Controls.Add(Type:=msoControlPopup)
    cbp1.Caption = "Subset3"
    Set cbb = cbp1.Controls.Add(Type:=msoControlButton)
    cbb.Caption = "Macro8"
    cbb.OnAction = "Macro8"
    cbb.Style = msoButtonCaption
    Set cbb = cbp1.Controls.Add(Type:=msoControlButton)
    cbb.Caption = "Macro9"
    cbb.OnAction = "Macro9"
    cbb.Style = msoButtonCaption
    Set cbb = cbp0.Controls.Add(Type:=msoControlButton)
    cbb.Caption = "Macro10"
    cbb.OnAction = "Macro10"
    cbb.Style = msoButtonCaption
    cbr.Visible = True
    Set cbp2 = Nothing
    Set cbp1 = Nothing
    Set cbp0 = Nothing
    Set cbb = Nothing
    Set cbr = Nothing

  3. #3
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: CommandBars (VBA/Word/2000 SP-3)

    Hans

    > You could do something like this

    I could! I did! It worked a treat!
    And now I understand a little better. Thank you Hans.
    Regards
    Don

  4. #4
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: CommandBars (VBA/Word/2000 SP-3)

    I can find no reference to passing arguments with the cbb.OnAction command.

    How does one pass arguments? Is it possible?

    T.I.A.
    Regards
    Don

  5. #5
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: CommandBars (VBA/Word/2000 SP-3)

    Typically the parameter is stored as a Tag to the control, the code can then access the value as
    CommandBars.ActionControl.Tag

    StuartR

  6. #6
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: CommandBars (VBA/Word/2000 SP-3)

    Thank you Stuart
    That was just what I needed.
    Regards
    Don

Posting Permissions

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