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

    Multiple toolbar being created (2000/Sr1)

    I am creating a toolbar and now I see everytime open a another word doc a get another copy of it. I know I need to unload it upon closing but currently I still have multiple copies. I need to get a collection of the existing toolbars, loop thru them and delete a specific named toolbar but one. I cannot find any example code.

    thanks

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

    Re: Multiple toolbar being created (2000/Sr1)

    What are the names of the toolbars? I thought there could be only one toolbar with a specific name?

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

    Re: Multiple toolbar being created (2000/Sr1)

    I gave it a name of "ELGI ". Well there are multiple toolbars with the same buttons showing up.

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

    Re: Multiple toolbar being created (2000/Sr1)

    I didn't know that the name of a toolbar doesn't have to be unique. Try this:

    Sub DeleteToolbarsButOne(strName As String)
    Dim intCount As Integer
    Dim i As Integer
    Dim cbr As CommandBar
    For Each cbr In CommandBars
    If cbr.BuiltIn = False Then
    If cbr.Name = strName Then
    intCount = intCount + 1
    End If
    End If
    Next cbr
    For i = 1 To intCount - 1
    CommandBars(strName).Delete
    Next i
    Set cbr = Nothing
    End Sub

    Call it as follows:

    DeleteToolbarsButOne "ELGI"

  5. #5
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Multiple toolbar being created (2000/Sr1)

    Hi Jim:
    Is it possible that you saved a copy of these toolbars in each of the documents? Or in multiple global templates? That would account for multiple toolbars. And, Hans, I could be wrong, but I thought you could have toolbars with the same name if the paths were different (i.e. different modules, projects, or templates). Is this incorrect?

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

    Re: Multiple toolbar being created (2000/Sr1)

    Phil,

    I did a small test, and - contrary to my expectations - was able to create an unlimited number of toolbars with the same name in Normal.dot, just by repeating the same instruction in a loop... Word must keep an internal ID.

  7. #7
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Multiple toolbar being created (2000/Sr1)

    Thanks for testing, Hans. I never tried (at least not deliberately) to create toolbars with the same name in the same template, project, & module. I get confused enough. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

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

    Re: Multiple toolbar being created (2000/Sr1)

    Jim,

    The code Hans has posted should get rid of the extra toolbars after the fact, but it would still be worthwhile to figure out why you are getting the multiple toolbars (per Phil's comment). Are you creating these toolbars manually or via code (sounds like the latter)? If via code, where is the code located? Would it be possible to post the relevant code?

    Gary

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

    Re: Multiple toolbar being created (2000/Sr1)

    Thanks. Yes I am creating the toolbar via VBA code a class as a matter of fact named "clsELGIToolBarMenu" and a instance of it is created in the template's Thisdocument object's open event and set to nothing in the close event. I am attaching it. Note I developed the dot on my laptop in steps where my first code was just to get the bar and buttons to appear and later I added code in the class to find all of the toolbars with the same name and delete them and then build them and I remove the bar in a call to the class from te Thisdocument's close event. After leaving this particualr dot file if I open a regular word doc I see multiple toolbars that created but my VBA code is not in there.
    Attached Files Attached Files

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

    Re: Multiple toolbar being created (2000/Sr1)

    Jim,

    Only had time for a quick look, here's something to try:

    In the 'createBarAndMenu' procedure in the class module, add the statement:

    <pre>CustomizationContext = ActiveDocument</pre>

    before the statement that adds the new commandbar.

    Haven't worked with these in a while, but I think what's happening is that if you do not specify the CustomizationContext, then the newly-created commandbar is going to be associated with Normal.dot by default. That would account for the multiple toolbars showing up when you open up other documents.

    Gary

Posting Permissions

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