I have added a commandbar button to my Word document and it works. However,
I want my button only visible in a subset of my open Word windows. How can
I turn the button visible for one group of Word windows and invisible for
others? I have tried using the WindowActivate and WindowDeactivate. The
deactivate does turn it off when I leave the window, but the Activate turns
it on whenever I go to a different Word window.
Thanks for any help.
Private Sub AppEventHandler_WindowActivate(ByVal Doc As Document, ByVal Wn
As Window)
Dim oMenuBar As CommandBar
Dim I As Integer
Set oMenuBar = CommandBars.Item("Standard")
For I = 1 To oMenuBar.Controls.Count
If I > 28 Then
I = I
End If
If oMenuBar.Controls(I).Caption = "&" + Hdr Then '"&MyGoTo" Then
'oMenuBar.Controls(I).Delete
oMenuBar.Controls(I).Visible = True
Exit For
End If
Next I
End Sub
Private Sub AppEventHandler_WindowDeactivate(ByVal Doc As Document, ByVal Wn
As Window)
Dim oMenuBar As CommandBar
Dim I As Integer
Set oMenuBar = CommandBars.Item("Standard")
For I = 1 To oMenuBar.Controls.Count
If I > 28 Then
I = I
End If
If oMenuBar.Controls(I).Caption = "&" + Hdr Then '"&MyGoTo" Then
'oMenuBar.Controls(I).Delete
oMenuBar.Controls(I).Visible = False
Exit For
End If
Next I
End Sub
Jonathan West - 15 Mar 2007 19:17 GMT
The simples approach to this sort ff thing is not to use code at all.
Instead, create a custom toolbar (commandbar) saved in your template, and
place buttons on that. The toolbar will only be available when a document
based on the template is the active document. If a document with a different
template is active, the toolbar disappears.

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
>I have added a commandbar button to my Word document and it works.
>However, I want my button only visible in a subset of my open Word windows.
[quoted text clipped - 66 lines]
>
> End Sub