Share via


How to: Programmatically hide worksheets

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

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.

Applies to: The information in this topic applies to document-level projects and VSTO Add-in projects for Excel. For more information, see Features available by Office application and project type.

Use 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

  1. 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
    

Use 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 a VSTO 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

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

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

See also