Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    CommandBar attached to template (WinXP / Word2003 NL)

    Is there a way to detect if a specific template has one or more custom CommandBars attached?
    I know you can test if there are custom CommandBars present using a For Each cb loop with the BuiltIn property. But if there are more documents open, I would like to be able to make any CommandBar invisible that sits in the AttachedTemplate of a specific document.

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

    Re: CommandBar attached to template (WinXP / Word2003 NL)

    The Context property of a commandbar is the full name (including the path) of the document or template in which the commandbar is stored. So you can take the Context property of a commandbar, extract the file name and compare it to the AttachedTemplate property of the document.

  3. #3
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: CommandBar attached to template (WinXP / Word2003 NL)

    Thanks Hans.

    I was after a generic solution to make all commandbars sitting in a specific document(attached template) invisible/disabled. To my surprise using For Each cb ActiveDocument.Commandbars listed all the commandbars that sit in the attached template of one of the opened documents, and not only the one for the specified document. Using the Context property makes it work. In case somebody is interested:

    <font face="Georgia">Sub ShowHideCBs(blnShow As Boolean, Optional Dok As Word.Document)
    Dim cb As CommandBar
    If Dok Is Nothing Then Set Dok = ActiveDocument
    For Each cb in Dok.CommandBars
    If cb.Context = Dok.AttachedTemplate.FullName Then
    cb.Visible = blnShow
    End If
    Next cb
    Set Dok = Nothing
    End Sub </font face=georgia>

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

    Re: CommandBar attached to template (WinXP / Word2003 NL)

    Yeah, that tripped me up the first time I tried it: ActiveDocument.CommandBars is the same as Application.CommandBars - the entire collection of available commandbars, not just those associated with the active document as I had expected.

Posting Permissions

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