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

    Add Command Bar (VBA/Word/2003)

    The following code (HansBar), is contained in a template (Template.dot), that is located on a server. A number of users have a shortcut to Template.dot in their Word STARTUP folder. There are no other files in the STARTUP folder.
    Template.dot contains an AutoExec.Main procedure. The first command in the AutoExec.Main procedure is Call HansBar.
    Intermittently, HansBar fails on the first Set command Set cbr = Application.CommandBars.Add(BarName, msoBarTop, False, True))
    Any thoughts on what the problem might be will be greatly appreciated. The complete module is attached if further details are required. <pre>Const LS = "CustomBars_05_08_30"
    ' Last saved as CustomBars_05_08_30.bas
    ' Reworked to accommodate update to Formastting lists
    ' 4 & 9 levels

    ' Last saved as CustomBars_05_08_28-1.bas
    ' AddBar and What_If procedures remmd out
    Option Explicit
    Const BarName = "GD Macros"
    Sub HansBar(Optional bHide As Boolean)

    Dim cbr As CommandBar
    Dim cbb As CommandBarButton
    Dim cbp0 As CommandBarPopup
    Dim cbp1 As CommandBarPopup
    Dim cbp2 As CommandBarPopup

    On Error Resume Next
    CommandBars(BarName).Delete
    On Error GoTo 0

    Set cbr = Application.CommandBars.Add(BarName, msoBarTop, False, True)
    Set cbp0 = cbr.Controls.Add(Type:=msoControlPopup)
    cbp0.Caption = "GD Macros"
    </pre>

    Regards
    Don

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

    Re: Add Command Bar (VBA/Word/2003)

    What error message do they get?

  3. #3
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    5,910
    Thanks
    0
    Thanked 89 Times in 85 Posts

    Re: Add Command Bar (VBA/Word/2003)

    I don't know a lot about the Word object model, but does it help if you change <code>CommandBars(BarName).Delete</code> to <code>Application.CommandBars(BarName).Delete</code>? I'm just wondering if a different CustomizationContext could cause your Delete operation to fail (silently because of the on error resume next) and then an error because you are trying to add a commandbar that already exists.
    Regards,
    Rory
    Microsoft MVP - Excel.

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

    Re: Add Command Bar (VBA/Word/2003)

    Method 'Add' of object "_CommandBars" Failed

    I have this from a poor quality screen capture that was forwarded to me and attached herewith.
    Regards
    Don

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

    Re: Add Command Bar (VBA/Word/2003)

    Thanks for the thought Rory. I will get the young lady who currently has the problem, to have a look-see for the existence of the Command bar, and advise. She's away from her post at the moment.
    Regards
    Don

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

    Re: Add Command Bar (VBA/Word/2003)

    Hi Rory
    Further to my last post; Subsequent to the macro failure, the "GD Macros" command bar does not exist.
    Regards
    Don

  7. #7
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    5,910
    Thanks
    0
    Thanked 89 Times in 85 Posts

    Re: Add Command Bar (VBA/Word/2003)

    Are there any similarities between the users who have the issue, or is it a mixture of users? (Do the users have write access to the template?)
    Regards,
    Rory
    Microsoft MVP - Excel.

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Add Command Bar (VBA/Word/2003)

    If the user launch Word directly from its program icon, does that work? If so, then it could be that the macro has problems in specific, limited contexts. These might include:

    (1) Launching a document from Internet Explorer
    (2) Word being launched by Outlook as a mail editor
    (3) Word is busy doing something else that affects the commandbars

    Just guesses...

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

    Re: Add Command Bar (VBA/Word/2003)

    The users that have exhibited this problem to date share the same building and in general have access to server(s) not accessed by others. The access rights to the template are Read-Only for all but a select few, and certainly all users that have exhibited the problem.
    Regards
    Don

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

    Re: Add Command Bar (VBA/Word/2003)

    Hi Jefferson
    The users are encountering this problem on launching Word. They launch either by clicking the Word icon in the Taskbar or double-clicking a docunent icon.
    Word should not be busy doing anything other than opening and responding to the AutoExec.Main commands.
    Word is not being used as the mail editor. I warned them all off that some time back.
    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
  •