Compartir a través de


WorkbookBase.Worksheets Property

Gets a Microsoft.Office.Interop.Excel.Sheets collection that represents all the worksheets in the workbook.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

Syntax

'Declaration
Public ReadOnly Property Worksheets As Sheets
public Sheets Worksheets { get; }

Property Value

Type: Microsoft.Office.Interop.Excel.Sheets
A Microsoft.Office.Interop.Excel.Sheets collection that represents all the worksheets in the workbook.

Remarks

This property does not return macro sheets, charts, or dialog sheets. Use the Sheets property to return those sheets as well as worksheets. You can also use the specialized properties Excel4MacroSheets and Excel4IntlMacroSheets to return macro sheets and the Charts property to return charts.

Examples

The following code example uses the Worksheets property to make the second worksheet in the current workbook invisible.

This example is for a document-level customization.

Private Sub HideSecondWorksheet()
    Dim worksheet As Excel.Worksheet = _
        CType(Me.Worksheets(2), Excel.Worksheet)
    worksheet.Visible = Excel.XlSheetVisibility.xlSheetHidden
End Sub
private void HideSecondWorksheet()
{
    Excel.Worksheet worksheet = (Excel.Worksheet)this.Worksheets[2];
    worksheet.Visible = Excel.XlSheetVisibility.xlSheetHidden;
}

.NET Framework Security

See Also

Reference

WorkbookBase Class

Microsoft.Office.Tools.Excel Namespace