By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,473 Members | 3,229 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,473 IT Pros & Developers. It's quick & easy.

Microsoft.Office.Interop.Excel.Worksheet & Named Fields

P: 1
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());
}
Dec 27 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.