Programmatically list all worksheets in a workbook
The Workbook class provides a Worksheets object. This object contains a collection of all the Worksheet objects in 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.
To list all existing worksheets in a workbook in a document-level customization
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.Controls.AddNamedRange( Globals.Sheet1.Range["A1"], "NamedRange1"); foreach (Excel.Worksheet displayWorksheet in Globals.ThisWorkbook.Worksheets) { NamedRange1.Offset[index, 0].Value2 = displayWorksheet.Name; index++; } }
To list all existing worksheets in a workbook in a VSTO Add-in
Iterate through the Worksheets collection and send the name of each sheet to a cell offset from a Range object.
Related content
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for