XL: How to Hide Sheets and Use xlVeryHidden Constant in a Macro

Last reviewed: February 3, 1998
Article ID: Q142530
The information in this article applies to:
  • Microsoft Excel 98 Macintosh Edition
  • Microsoft Excel 97 for Windows
  • Microsoft Excel for Windows 95, versions 7.0, 7.0a
  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for the Macintosh, version 5.0, 5.0a
  • Microsoft Excel for the Power Macintosh, versions 5.0, 5.0a

SUMMARY

In Microsoft Excel, you can hide sheets in a workbook so that a user will not see them. You can hide any sheet type in a workbook, but you must always leave at least one sheet visible.

MORE INFORMATION

Hiding a Sheet Using Menu Commands

To hide a sheet, point to Sheet on the Format menu, and then click Hide. To unhide a sheet, on the Format menu, point to Sheet, and then click Unhide.

NOTE: For module sheets in Microsoft Excel 5.0 and 7.0, point to Sheet on the Edit menu, and click Hide or Unhide. Module sheets in Microsoft Excel 97 and Microsoft Excel 98 cannot be hidden or unhidden, since they appear in the Visual Basic Editor.

Hiding a Sheet with a Visual Basic Macro

You can also hide or unhide a sheet using a Visual Basic for Applications macro or procedure. When you use Visual Basic code, you can use the "xlVeryHidden" property to hide a sheet and keep it from being listed in the Unhide dialog box. When you do this, the only way to make the sheet visible again is to create another Visual Basic macro.

In a Visual Basic macro, use the Visible property to hide or unhide a sheet. The Visible property can be set to True, False, or xlVeryHidden. True and False have the same effect as using the Unhide or Hide menu commands. The xlVeryHidden argument hides the sheet and also keeps it from being displayed in the Unhide dialog box.

The following examples show you how to use the Visible property of a Sheet object.

Microsoft 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 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 needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/support/supportnet/refguide/default.asp

Sample Visual Basic Code for All Versions

   Sub UnhideSheet()
       Sheets("Sheet1").Visible = True
    End Sub

    Sub HideSheet()
       Sheets("Sheet1").Visible = False
    End Sub

Sample Visual Basic Code for Versions 5.0 and 7.0

NOTE: You cannot hide or unhide module sheets in Microsoft Excel 97 or Microsoft Excel 98.

   Sub VeryHideSheet()
       Sheets("Module1").Visible = xlVeryHidden
   End Sub

For additional information, please see the following article(s) in the Microsoft Knowledge Base:

   ARTICLE-ID: Q156879
   TITLE     : XL97: Visual Basic Modules Cannot Be Hidden or Protected

   ARTICLE-ID: Q128192
   TITLE     : XL5: Can't Insert Sheet Based on Template with Hidden
               Sheet

   ARTICLE-ID: Q128373
   TITLE     : XL5: Macro Cannot Determine If Sheet Is VeryHidden

   ARTICLE-ID: Q127944
   TITLE     : XL: Sheet Based on Template with Hidden Sheet Not
               Inserted

   ARTICLE-ID: Q131551
   TITLE     : XL5: Macro Cannot Set Module to xlVeryHidden


Additional query words: 5.00 7.00 8.00 XL98 XL97 XL7 XL5
Keywords : kbcode kbprg PgmHowto
Version : WINDOWS:5.0,5.0c,7.0,97; MACINTOSH:5.0,5.0a,98
Platform : MACINTOSH WINDOWS
Issue type : kbhowto


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 3, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.