XL97: Visible Property Does Not Apply to All CommandBars

Last reviewed: February 27, 1998
Article ID: Q166101
The information in this article applies to:
  • Microsoft Excel 97 for Windows

SYMPTOMS

When you attempt to hide or show a commandbar in a Visual Basic for Applications macro you may receive the following error message:

   Run-time error '-2147467259 (80004005)':
   Method 'Visible' of object 'CommandBar' failed

CAUSE

This problem will occur if you attempt to hide or show a Commandbar to which the Visible property does not apply.

WORKAROUND

Microsoft provides examples of Visual Basic for Applications procedures 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. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

The following example will loop through all of the CommandBars and display the CommandBar name in a message box, without generating the error message mentioned above.

NOTE: The "MsgBox ComBar.Name" line in the macro below is for demonstration purposes. There are over 80 CommandBars 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 will receive the error message mentioned above.

MORE INFORMATION

Not all of the CommandBar items support the Visible property. Below is a list of CommandBar items that are known to generate the error message mentioned above, 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 CommandBars are used for context-sensitive menus and items such as the current list of sheets in a workbook.


Additional query words: XL97 xl97vbmigrate
Keywords : kberrmsg kbprg
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kberrmsg


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 27, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.