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



The information in this article applies to:

  • Microsoft Excel 98 Macintosh Edition
  • Microsoft Excel 97 for Windows
  • Microsoft Excel for Windows 95
  • Microsoft Excel for Windows 95 7.0a
  • Microsoft Excel for Windows 5.0
  • Microsoft Excel for Windows 5.0c
  • Microsoft Excel for the Macintosh 5.0
  • Microsoft Excel for the Macintosh 5.0a
  • Microsoft Excel for the Power Macintosh 5.0
  • Microsoft Excel for the Power Macintosh 5.0a

This article was previously published under Q142530

SUMMARY

In Microsoft Excel, you can hide sheets in a workbook so that a user cannot 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, point to Sheet on the Format menu, 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. You cannot hide or unhide module sheets in Microsoft Excel 97 and Microsoft Excel 98 Macintosh Edition, because 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 Microsoft 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 the Unhide dialog box from listing it. 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. You can set the Visible property 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 the Unhide dialog box from displaying it.

Sample Visual Basic Code for All Versions

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 samples show you how to use the Visible property of a Sheet object.
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 Macintosh Edition.
Sub VeryHideSheet()
    Sheets("Module1").Visible = xlVeryHidden
End Sub
				

REFERENCES

For additional information, please click the article numbers below to view the articles in the Microsoft Knowledge Base:

156879 XL97: Visual Basic Modules Cannot Be Hidden or Protected

128192 XL5: Can't Insert Sheet Based on Template with Hidden Sheet

128373 XL5: Macro Cannot Determine If Sheet Is VeryHidden

127944 XL: Sheet Based on Template with Hidden Sheet Not Inserted

131551 XL5: Macro Cannot Set Module to xlVeryHidden


Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbdtacode kbhowto kbProgramming KB142530