I have an Excel Workbook that has several worksheets in it. The tables in the worksheets have been assigned names using the Name Manager in Excel. Is there a way to get a list of these table names, instead of the worksheet names?
For instance, where workbook is defined as a Microsoft.Office.Interop.Excel.Workbook:
var names = (workbook.Names as System.Collections.IEnumerable).Cast<Name>();
returns a list of defined name ranges in the workbook. Additionally:
var worksheets = workbook.Worksheets.Cast<Worksheet>();
returns a list of worksheets in the workbook, whose names are the same as the tab names of the worksheets.
Neither of these list the tables by their assigned names. They only list the tables by their worksheet name. I hope I’ve made the question clear enough, but I can provide an example if need be.
For historical reasons, Tables in Excel are called Lists in the OM.
What you are looking for are
ListObjectson aWorksheet. A ListObject has a Range object attached to it, which you can use to figure out the name.DisplayNamemay return the name as well – I am not sure.