Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Two strange CommandBar problems (Word 2000)

    I'm changing the way my application uses command bars, and and I've encountered a couple of baffling behaviors.

    The first one concerns CustomizationContext. As I understand it, this application property determines the scope of subsequent changes made to command bars. In some cases it has a side effect: I set it to the active document, and the active document's command bar disappears. I can't find anything in the documentation which suggests why that should happen!

    The other problem concerns the CommandBars object's FindControl method. I set the Tag property to identify certain buttons whose captions must be changed dynamically, then I use FindControl to find them. For some reason the tags keep disappearing spontaneously. I can display a button's Tag value after setting it and see that is correct; when I need it some time later, it's gone.

    The really weird part of this one is that one control's tag never disappears; all of the others seem to disappear together. The one that doesn't disappear is on the first control in each command bar, which is a dropdown list, and is defined immediately after the command bar is defined. The tags that do disappear are all in buttons, which are defined a little later in the code.

    I wondered whether these two problems might be related: the tags are disappearing because the customization context is set incorrectly, or is not set when it should be. I think that cannot be the case; I define each control's Tag value when I define the control, so if the Tag value disappeared for that reason, the control itself would have to disappear too.

  2. #2
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Two strange CommandBar problems (Word 2000)

    I probably can't answer all your questions, but as a start:

    > The first one concerns CustomizationContext. [,,,]

    If you set the customization context to the active document, you should see all toolbars that are currently set to "visible" in the document (= that have a check mark in the "Customize" dialog, "Toolbars" tab).
    With customization context set to normal.dot or the attached template, you'll see all the toolbars that would be visible if you created a new document based on that template.

    So switching the customization context, some toolbars may appear while others vanish.

    > The other problem concerns the CommandBars object's FindControl method. [...]

    You may well have different buttons with the same ID (on different toolbars, sub-menus, or context menus), and each of them can have the same ".Tag" property, or a different ".Tag" property.
    ".FindControl" will give you the first one with the specified ID, and Tag.
    If you want to make sure you get the right button, you may need to use ".FindControls", loop through the found controls, and check the ".Parent" property to locate the button on your toolbar.
    In case the controls have the same ID and the same tag, you may need to distinguish between them by looking at their position, or .OnAction, or something else.
    IIRC, buttons for macros which you add yourself for example all get the ID:=1, so .FindControl wouldn't suffice if several of them use the same Tag property.

    Instead of using ".FindControl(s)", you could start with your toolbar, and loop only the Controls/Buttons on that toolbar.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  3. #3
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Two strange CommandBar problems (Word 2000)

    I appreciate your effort to answer my questions, but it's not clear to me how the information you gave relates to them.

    Your statement about CustomizationContext agrees with my experience (but not with Microsoft's documentation): the setting affects which command bars are visible, as well as (instead of?) the scope of subsequent changes.

    I never set the customization context to a template; I only set it to various open documents (not necessarily to a document which is active at the time it is set). It's not clear how I can do that without making command bars appear and disappear according to "logic" which has nothing to do with the needs of my program.

    I understand exactly how FindControl is supposed to work -- at least, my understanding entirely agrees with what you said about it. I'm trying to figure out why the Tag values I set spontaneously disappear after I set them, and how to prevent that from happening.

  4. #4
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Two strange CommandBar problems (Word 2000)

    Sorry, I don't understand you at all. Perhaps somebody else can jump in to help you?

    If you change the customization context, it wouldn't make the slightest sense to display anything else than the toolbars like they are saved in the document/template you currently customize.
    I don't see either where the documentation says they should.
    You might check here in which order the customizations are applied: How Word Resolves Conflicts (they forgot "0. Document", I guess).

    I also can't follow how the way Word behaves when you customize a toolbar can conflict with the logic of any program you run.

    And I've never seen Tag values to "disappear spontaneously" (after you changed it? after you closed and reopened the document?)

    Finally I don't understand why you use FindControl if you agree it's problematic.

    Perhaps you should post some of the code you are using to change the tag property of the buttons on the toolbar.

    <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15> Klaus

  5. #5
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Two strange CommandBar problems (Word 2000)

    Knew I'd forget something...

    > I never set the customization context to a template; I only set it to various open documents

    You can't store a toolbar in a document, so I don't see the sense in that.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  6. #6
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Two strange CommandBar problems (Word 2000)

    I'll try to clarify things a little more.

    >If you change the customization context, it wouldn't make the slightest sense to display anything
    >else than the toolbars like they are saved in the document/template you currently customize.

    Sorry, but I don't understand what part of my message this relates to.

    >You might check here in which order the customizations are applied: How Word Resolves Conflicts...

    That topic talks about precedence among templates and the "application layer," which comes last. The contents of all of my toolbars and are defined at runtime, so everything is happening in the "application layer" (and assuming that somewhat cryptic term means what I think). Without some information about precedence WITHIN the application layer, this doesn't help.

    >I also can't follow how the way Word behaves when you customize a toolbar can conflict
    >with the logic of any program you run.

    I was not speaking of the logic in my program -- I was speaking of logic of Word's toolbar display, which Word is imposing on my program.

    >And I've never seen Tag values to "disappear spontaneously" (after you changed it?
    >after you closed and reopened the document?)

    I didn't say when the Tag values disappear because I don't know. They disappear while nothing in particular is happening, except that parts of my code are running. I might be able to identify the cause by "binary search" debugging. (Does it happen before or after point X? If after point X, before or after point Y?) I did not try to do so because it would have been a tremendous amount of work, and I was not confident that knowing where it happens would bring me any closer to understanding how to make it stop.

    >Finally I don't understand why you use FindControl if you agree it's problematic.

    Well, since I wrote the first message in this thread, I have ceased to do so. I was trying to use it because it provides a built-in tool for performing a necessary task, and since I couldn't use it, I had to reinvent it.

    >Perhaps you should post some of the code you are using to change the tag property of the buttons on the toolbar.

    Not practical, unfortunately. The program has evolved much like a conventional GUI application, with lots of small event handlers that make no sense when seen in isolation. I don't think there's a relevant piece of code I could post that would make sense; to provide the necessary context it would have to be huge. I could create an example, as one would do for a programming text, but designing, writing, and verifying the example would also be a tremendous amount of work.

    >> never set the customization context to a template; I only set it to various open documents

    >You can't store a toolbar in a document, so I don't see the sense in that.

    Now, I KNOW that isn't true. The whole reason for the code I'm trying to debug is to ensure that when I update a global option setting which affects the appearance of a toolbar, the toolbar is updated in every open document which displays it, not just in the one that is active at the time. That's not a problem I imagined; I wrote the code to solve it because it was happening to me.

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

    Re: Two strange CommandBar problems (Word 2000)

    I can confirm some of what you have observed.

    I can set the CustomizationContext to a document and create a commandbar. If I then set the CustomizationContext to the AttachedTemplate then the new commandbar "disappears". A quick check in the immediate window shows that it still exists, but it's Visible property has been set to False. Changing it back to True brings it visible again without changing the customisation context.

    I saved the document with the attached commandbar and when I reopoened it then the commandbar was now visible - even though the customizationcontext is still set to be Normal.Dot. Specifying customizationcontext = ActiveDocument.AttachedTemplate caused the commandbar to dissappear again, although I could bring it back again with Application.CommandBars("barTest").Visible = True


    I really don't understand what you are saying about Tags. One thing I would like to understand so we can help you is whether every CommandBar has a unique name or whether Word is trying to merge multiple CommandBars from templates and documents.

    StuartR

  8. #8
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Two strange CommandBar problems (Word 2000)

    >>You can't store a toolbar in a document, so I don't see the sense in that.
    > Now, I KNOW that isn't true.

    You are right. Hadn't ever done that.

    <img src=/S/blush.gif border=0 alt=blush width=15 height=15> Klaus

  9. #9
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Two strange CommandBar problems (Word 2000)

    >>I really don't understand what you are saying about Tags. One thing I would like to understand so we can help you is whether every CommandBar has a unique name or whether Word is trying to merge multiple CommandBars from templates and documents.

    Stu, baby, I won't be a bit surprised if you nailed the problem with that comment...
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  10. #10
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Two strange CommandBar problems (Word 2000)

    >One thing I would like to understand so we can help you is whether every CommandBar has a unique name or whether Word is trying to merge multiple CommandBars from templates and documents.

    In context of the problem I've described I don't understand why that's significant -- whatever weird consequences my command bar definitions have, they should not change spontaneously once set up. I can see that changing one document's command bar could have on unintended effects on another with the same name if the setup is done wrong, but that's not the case here. The tag values disappear during a period when NO document's command bar has been modified.

    But I'll try to answer the question. My application works with two or three different types of documents, and each one has a distinct command bar with a distinct name. All of the documents of a given type have command bars with the same name. Since I'm defining them in the documents, not in the template, that should not matter.

    Looking at the template, I see that all of the command bars are now defined there. Thus, Word might be trying to "merge" the toolbars from the template into the ones I create in the documents. Again, it seems to me that this should not matter; if it were a problem the toolbars would be created incorrectly. They would not "go bad" later.

    My program does not need the toolbar definitions in the template, and I would be happy to delete them if that would help solve the problem. But it's unclear how I would prevent them from coming right back, since the behavior of CustomizationContext seems in part to be either undocumented or capricious.

    In my first post I think I mentioned that the tags for the dropdown list and start of each command bar was behaving itself, while the tags for all of the following buttons were disappearing. That's no longer true. Yesterday the dropdown list "broke," and I found that its tag was now disappearing, too. I modified my button-finding subroutine to find any type of command bar control that has a caption, and now I am not using tags at all.

    I confess that solving this puzzle no longer is a high priority for me, although I would still like to get to the bottom of it. I was originally trying to make FindControl work in order to avoid re-inventing it. Now that I have re-invented it, the problem has become academic.

  11. #11
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Two strange CommandBar problems (Word 2000)

    >>I confess that solving this puzzle no longer is a high priority for me...

    And I think that since you can't post any code, we've no choice but to adopt your position.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  12. #12
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Two strange CommandBar problems (Word 2000)

    in my previous post I may have given you the wrong impression about why I'm declining to post code. I think I came across as saying, "It's too much trouble." I meant to say, "I don't know what I could post with any reasonable amount of effort that would be useful."

    I could easily post the subroutine that builds the command bars, but that probably wouldn't help because I can display the tag values after it runs and see that they are correct.

    I can't post the code in which the tag values disappear, because I don't know when or where it happens. If I did, I could probably solve the problem myself in short order.

    I theoretically could post the entire application, but it contains over 6000 lines of code in about a dozen modules. Leaving aside the question of whether I'm willing to give it away, I don't think anyone else would want to rummage through it for me.

    That said, I think you're correct that you're not in a good position to help me, and the mystery is best left unsolved.

  13. #13
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Two strange CommandBar problems (Word 2000)

    Still, you've whetted the problem solving brains of a number of very good
    code "puzzlers" who are struck (at least temporarily) by your dilemma and
    can't help but try to solve it -- for the benefit of all.

    I would still like to see the code that creates the toolbars for at least
    two of your documents or templates. You newer know what another eye or two
    might notice -- it just may be the golden nugget (or lack thereof). Would you
    post two of the templates or docs or at least the toolbar creating subs from those?

    It might not be as un-useful as you suspect. Give it a go.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  14. #14
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Two strange CommandBar problems (Word 2000)

    Okay, I'll play along.

    I can't get the server to display my code examples with leading spaces for indentation -- depending on how I submit the message it either removes the spaces completely or displays the HTML "no-break space" code -- so I'm storing the whole message in a file and attaching it.

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

    Re: Two strange CommandBar problems (Word 2000)

    I can't see anything ovbiously wrong, but can you clarify a couple of things.

    What does barType = docType(doc) do?
    Where is the code that adds the first control to the command bar?

    StuartR

Page 1 of 2 12 LastLast

Posting Permissions

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