WD2002: Cannot Programmatically Hide Custom Command Bar (220731)
The information in this article applies to:
This article was previously published under Q220731 SYMPTOMS
In Microsoft Word, when you create a Microsoft Visual Basic for Applications macro to make a new command bar, and the macro dictates that the command bar be invisible, the command bar remains visible.
This behavior is different than in versions of Word earlier than Word 2000.
CAUSEMicrosoft provides programming examples for illustration only, without warranty either
expressed or implied, including, but not limited to, the implied warranties of
merchantability and/or fitness for a particular purpose. This article assumes
that you are familiar with the programming language being demonstrated and the
tools used to create and debug procedures. Microsoft support professionals can
help explain the functionality of a particular procedure, but they will not
modify these examples to provide added functionality or construct procedures to
meet your specific needs. If you have limited programming experience, you may
want to contact a Microsoft Certified Partner or the Microsoft fee-based
consulting line at (800) 936-5200. For more information about Microsoft Certified
Partners, please visit the following Microsoft Web site:
For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:
This behavior can occur when you create a second document with the Add method, in which case, a command bar is created for each document. A command bar named Toolbar1 is created and commanded to be invisible through the following code
Sub Test()
Dim newToolbar As CommandBar
Set newToolbar = CommandBars.Add(Name:="Toolbar1", _
Position:=msoBarFloating, Temporary:=True)
newToolbar.Visible = True
newToolbar.Left = 400
newToolbar.Top = 125
Documents.Add
newToolbar.Visible = False
End Sub
however, a similar command bar created with the following line of code remains visible:
Documents.Add
WORKAROUND
To work around this issue, on the View menu, point to Toolbars, and then click to clear the check box next to the toolbar that you want to be invisible.
RESOLUTION
To resolve this issue, you need to add code to a macro that makes the toolbar invisible on each document that the toolbar is added to, as in the following macro:
Sub Test()
Dim newToolbar As CommandBar
Set newToolbar = CommandBars.Add(Name:="Toolbar1", _
Position:=msoBarFloating, Temporary:=True)
newToolbar.Visible = True
newToolbar.Left = 400
newToolbar.Top = 125
Documents.Add
newToolbar.Visible = False
Set cbs = Application.ActiveDocument.CommandBars
cbs("Toolbar1").Visible = False
End Sub
Note that the added lines of code cause the toolbar on the active document to be invisible.
REFERENCESFor more information about programmatically adding command bars, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type addmethod (command bars collection) in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
Modification Type: | Minor | Last Reviewed: | 10/11/2006 |
---|
Keywords: | kbprb KB220731 |
---|
|