Results 1 to 13 of 13
  1. #1
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    CustomizationContext Articles? (2000 2002 2003)

    Anybody know any good, complete articles which explain and provide examples of CustomizationContext?

    Thanks...

    Dan

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

    Re: CustomizationContext Articles? (2000 2002 2003)

    I think the online help says pretty much what there is to say about CustomizationContext...

  3. #3
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CustomizationContext Articles? (2000 2002 2003)

    Okay--here's our problem. We create a class-wide reference to a commandbar:

    set m_objCommandBar = CommandBars.Add("MyToolBar")

    If we set m_objCommandBar.Visible=True immediately after this line of code, then "MyToolbar" becomes visible (as we would expect).

    If, however, we open a new document, and then call a method on the above class that sets m_objCommandBar.Visible = False, the m_objCommandBar.Visible property does appear to be "False", but the command bar does not get hidden. On the other hand, if we change to hide method to be the following:

    CommandBars("MyToolbar").Visible=False

    Then the toolbar does get hidden properly.

    The question is: why doesn't m_objCommandBar.Visible=FALSE work as expected (as opposed to CommandBars("MyToolbar").Visible=False)?

    One interesting side note to this is that objptr(m_objCommandBar) does *not* equal objptr(CommandBars("MyToolBar")), which makes it seem like they are not pointing to the same object. Another interesting point is that this behavior only occurs if we open an additional document.

    Thanks for your help...

    Dan

  4. #4
    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: CustomizationContext Articles? (2000 2002 2003

    Can you post a little class that I could import into a project to try to see how this works? (A .cls renamed to .txt would be especially convenient.)

  5. #5
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CustomizationContext Articles? (2000 2002 2003

    Here's some sample code. Add it to a VB project with the Word and Office class libraries referenced. After instantiating the class, you'll have a test toolbar displayed. Examine what happens in the class's m_appWord_DocumentChange event after you add a new document. You can follow the debugging statements best by viewing them in dbgview (from www.sysinternals.com).

    Thanks...

    Dan
    Attached Files Attached Files

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

    Re: CustomizationContext Articles? (2000 2002 2003

    In this specific example, you don't need the DocumentChange event (and hence, m_appWord doesn't have to be declared WithEvents), if you create the document first and set the CustomizationContext to the document:

    Private Sub Class_Initialize()
    Dim objButton As Office.CommandBarButton
    Set m_appWord = New Word.Application
    Set m_objDoc = m_appWord.Documents.Add
    m_appWord.CustomizationContext = m_objDoc
    Set m_objCommandBar = m_appWord.CommandBars.Add("MyToolbar")
    Set objButton = ...
    ...
    End Sub

    Since the CustomizationContext has been set to m_objDoc, Word itself will take care of hiding the toolbar if another document is activated, and showing it when m_objDoc is activated again.

    I won't pretend to understand the behavior of the object pointers.

  7. #7
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CustomizationContext Articles? (2000 2002 2003

    Thanks Hans. That's useful information. However, I'd still like to know why the code I posted doesn't behave as expected...Dan

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

    Re: CustomizationContext Articles? (2000 2002 2003

    I'm afraid I don't know. I'll be interested too if someone else can shed light on this.

  9. #9
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CustomizationContext Articles? (2000 2002 2003

    Hi. Have you had a chance to look at my sample code? Do you have any thoughts on what might be causing the behavior? Thanks...Dan

  10. #10
    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: CustomizationContext Articles? (2000 2002 2003

    I've looked <img src=/S/grin.gif border=0 alt=grin width=15 height=15> -- but I can't figure out how to test it easily.

    In thinking about this and playing with simple blank documents, I've reached the following conclusions.

    Generally speaking, unless you specify a different container, changes you make to CommandBars are going to affect Normal.dot. If you create a blank Document1 based on Normal.dot and display an existing toolbar, such as Frames, or add a new toolbar, such as Custom1, and then press Ctrl+N to create a new blank Document2 based on Normal.dot, the same toolbar will be displayed. However, closing the toolbar in the context of one document does not close it in the context of the other.

    Like the importation of styles into a new blank document, the state of the commandbar container(s) is captured at the moment of creation, but then the document is an independent context. This is not to say that deleting the toolbar would not have any effect; it certainly does. But the visibility of the toolbar appears no longer to be associated with the setting in the template or in the document that was active at the time it was created.

    If true, this means your code shouldn't work, which is what you are experiencing. Does that create a real problem?

  11. #11
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CustomizationContext Articles? (2000 2002 2003

    Thanks so much for your thoughtful response! It helped me quite a bit in thinking through this situation.

    The problem came up as we were writing an app which coordinated three sets of documents, each of which had their own commandbar, which had to be shown or hidden based on what type of document was currently in focus. I think we'll be able to get around this problem by hiding the commandbars via application.commandbars("MyToolBar").Visible =True. However, I remain puzzled about why this seems to work--unless by using the application.commandbars collection, you "overrule" the contexts of the individual documents. Interesting problem...

  12. #12
    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: CustomizationContext Articles? (2000 2002 2003

    I think Application.CommandBar("Whatever").Visible = False works on the context of the ActiveDocument. If Document2 is active and you execute that code, the toolbar should disappear from Document2 only, and not Document1. In your previous scenario, the likely effect was that the toolbar would disappear from the context of Document1 and not Document2. Is it consistent that way?

    To get back to the CustomizationContext, this would let you improve the targeting of your CommandBar in the first place. Let's say you want it to appear only for Document1 and Document1 has a unique attached template. That template would be a logical candidate for being the CustomizationContext. If Document1 is based on Normal.dot, then making Document1 the CustomizationContext makes more sense. The attached document, which contains a macro and button to run it (and a less than ideal method of using Stop statements to pause for viewing...) illustrates this option.
    Attached Files Attached Files

  13. #13
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CustomizationContext Articles? (2000 2002 2003

    Thanks very much. I will take a look at the document and think about your proposed solution....Dan

Posting Permissions

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