Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2007

Tip: Looking for answers? Try searching our database.

Limit a CommandBar Button Availability in Word

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeffrey Grantz - 15 Mar 2007 17:52 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.