This documentation is archived and is not being maintained.

How to: List All Worksheets in a Workbook


Some code examples in this topic use the this or Me keyword or the Globals class in a way that is specific to document-level customizations, or they rely on features of document-level customizations such as host controls. These examples can be compiled only if you have the required applications installed. For more information, see Features Available by Product Combination.

The Microsoft.Office.Interop.Excel.Workbook class provides a Microsoft.Office.Interop.Excel.Worksheets object. This object contains a collection of all the Microsoft.Office.Interop.Excel.Worksheet objects in the specified workbook.

To list all existing worksheets in a workbook

  • Iterate through the Worksheets collection and send the name of each sheet to a cell offset from a NamedRange control.

    private void ListSheets()
        int index = 0;
        Microsoft.Office.Tools.Excel.NamedRange NamedRange1 =
            Globals.Sheet1.Range["A1", missing], "NamedRange1");
        foreach (Excel.Worksheet displayWorksheet in Globals.ThisWorkbook.Worksheets)
            NamedRange1.Offset[index, 0].Value2 = displayWorksheet.Name;

See Also