Dela via


How to: Hide Worksheets

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

  • Application-level projects

Microsoft Office version

  • Excel 2003

  • Excel 2007

For more information, see Features Available by Application and Project Type.

You can show or hide any worksheet in a workbook. To hide a worksheet, use the worksheet host item or access the worksheet by using the sheets collection of the workbook.

Using the Worksheet Host Item

If the worksheet was added at design-time in a document-level customization, use the Visible property to hide the specified worksheet.

To hide a worksheet using a worksheet host item

  • Set the Visible property of the Sheet1 host item to the xlSheetHidden enumeration value.

    Globals.Sheet1.Visible = Excel.XlSheetVisibility.xlSheetHidden
    
    Globals.Sheet1.Visible = Excel.XlSheetVisibility.xlSheetHidden;
    

Using the Sheets Collection of the Excel Workbook

Access worksheets through the Microsoft Office Excel Sheets collection in the following cases:

  • You want to hide a worksheet in an application-level add-in.

  • The worksheet that you want to hide was created at run time in a document-level customization.

To hide a worksheet using the Sheets collection of the Excel workbook

  • Set the Visible property of the worksheet to the xlSheetHidden enumeration value.

    CType(Globals.ThisWorkbook.Sheets(1), Excel.Worksheet) _
        .Visible = Excel.XlSheetVisibility.xlSheetHidden
    
    ((Excel.Worksheet) Globals.ThisWorkbook.Sheets[1])
        .Visible = Excel.XlSheetVisibility.xlSheetHidden;
    

See Also

Tasks

How to: Delete Worksheets from Workbooks

How to: Move Worksheets Within Workbooks

How to: Protect Worksheets

Concepts

Working with Worksheets

Host Items and Host Controls Overview

Global Access to Objects in Visual Studio Tools for Office Projects