I want to be able to get a list of all custom named fields in an Excel worksheet, but I am having trouble with this. In the code below, access to a field that I named "DEALCODE" works fine - I get the value. When I try to get a collection of named cells in the loop below, I come up with only one entry: 'Portfolio Company Information'!Print_Area
The part before the ! is obviously my sheet name, but I have a whole slew of custom named cells in the sheet and I want to get a list. What am I doing wrong here? Thanks in advance!
Code snippet:
Workbook currentCompanyFile = xlApp.Workbooks.Open(current_fileNameDir, false, true, 5, "", "", true, XlPlatform.xlWindows, "", true, false, 0, true, true, false);
Sheets allSheetsInCurrentBook = currentCompanyFile.Worksheets;
Microsoft.Office.Interop.Excel.Worksheet first_sheet = (Microsoft.Office.Interop.Excel.Worksheet)allSheet sInCurrentBook.get_Item(wsName_1);
//this works, gets the value of a named field called 'DEALCODE'
xlApp.Goto("DEALCODE", false);
deal_code = xlApp.ActiveCell.FormulaR1C1.ToString();
//i want this to return all the named fields, including 'DEALCODE', but
//it returns only 'Print_Area'
foreach (Name this_name in first_sheet.Names)
{
Console.WriteLine(this_name.Name.ToString());
}