title | description | titleSuffix | ms.date | ms.topic | dev_langs | helpviewer_keywords | author | ms.author | manager | ms.subservice | ||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Programmatically list all worksheets in a workbook |
Learn how you can programmatically list all worksheets in a Microsoft Excel workbook by using Visual Studio. |
02/02/2017 |
how-to |
|
|
John-Hart |
johnhart |
mijacobs |
office-development |
The xref:Microsoft.Office.Interop.Excel.Workbook class provides a xref:Microsoft.Office.Interop.Excel.Worksheets object. This object contains a collection of all the xref:Microsoft.Office.Interop.Excel.Worksheet objects in the workbook.
[!INCLUDEappliesto_xlalldocapp]
-
Iterate through the xref:Microsoft.Office.Interop.Excel.Worksheets collection and send the name of each sheet to a cell offset from a xref:Microsoft.Office.Tools.Excel.NamedRange control.
:::code language="csharp" source="../vsto/codesnippet/CSharp/Trin_VstcoreExcelAutomationCS/Sheet1.cs" id="Snippet21":::
-
Iterate through the xref:Microsoft.Office.Interop.Excel.Worksheets collection and send the name of each sheet to a cell offset from a xref:Microsoft.Office.Interop.Excel.Range object.
:::code language="csharp" source="../vsto/codesnippet/CSharp/trin_vstcoreexcelautomationaddin/ThisAddIn.cs" id="Snippet13":::