Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

XL2002: Visible Property Does Not Apply to All CommandBars


View products that this article applies to.

This article was previously published under Q291068
For a Microsoft Excel 2000 version of this article, see 213716 (http://support.microsoft.com/kb/213716/EN-US/).
For a Microsoft Excel 97 version of this article, see 166101 (http://support.microsoft.com/kb/166101/EN-US/).

↑ Back to the top


Symptoms

When you attempt to hide or show a CommandBar object in a Microsoft Visual Basic for Applications macro, you may receive the following error message:
Run-time error '-2147467259 (80004005)'
Method 'Visible' of object 'CommandBar' failed

↑ Back to the top


Cause

This problem occurs if you attempt to hide or show a command bar to which the Visible property does not apply.

↑ Back to the top


Workaround

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements. The following example loops through all of the command bars and displays the command bar name in a message box, without generating the error message mentioned earlier.

NOTE: The "MsgBox ComBar.Name" line in the macro below is for demonstration purposes. There are over 80 command bars that use the Visible property, so you will receive over 80 message boxes. Remove this line if the macro is taking too long to run.
Sub Command_Bars()
    On Error Resume Next
    For Each ComBar In Application.CommandBars
        ComBar.Visible = False
        MsgBox ComBar.Name
    Next ComBar
End Sub
				
An On Error statement was inserted before the For Each loop. If you run the macro without the On Error statement, you receive the error message mentioned earlier.

↑ Back to the top


Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

↑ Back to the top


More information

Not all of the CommandBar items support the Visible property. The following list contains CommandBar items that are known to generate the error message mentioned earlier, when used with the Visible property.
   Index   CommandBar
   --------------------------------
   19      Query and Pivot
   20      Workbook tabs
   21      Cell
   22      Column
   23      Row
   24      Cell
   25      Column
   26      Row
   27      Ply
   28      XLM Cell
   29      Document
   30      Desktop
   31      Nondefault Drag and Drop
   32      AutoFill
   33      Button
   34      Dialog
   35      Series
   36      Plot Area
   37      Floor and Walls
   38      Trendline
   39      Chart
   40      Formula Bar
   41      PivotTable Context Menu
   42      Query
   43      Query Layout
   44      AutoCalculate
   45      Object/Plot
   46      Title Bar (Charting)
   47      Layout
   70      Shapes
   71      Inactive Chart
   72      Excel Control
   73      Curve
   74      Curve Node
   75      Curve Segment
   76      Pictures Context Menu
   77      OLE Object
   78      ActiveX Control
   79      WordArt Context Menu
   80      Rotate Mode
   81      Connector
   82      &Wizard
   83      Add Command
   84      Built-in Menus
   85      System
				
These command bars are used for shortcut menus and items such as the current list of sheets in a workbook.

↑ Back to the top


Keywords: KB291068, kbprogramming, kbpending, kberrmsg, kbdtacode, kbbug

↑ Back to the top

Article Info
Article ID : 291068
Revision : 6
Created on : 1/31/2007
Published on : 1/31/2007
Exists online : False
Views : 229