user3842389
user3842389

Reputation: 45

Get name of the named range corresponding to the given range

How can I get name of the Excel named range from cell range?

For example, I'm naming "A1" cell as "Test" in Excel editor, then I want to get this name in C# from "A1" Excel range.

Following is what I tried but it`s not giving me the result I require.

Xcelrng = (Excel.Range)Excel.Application.Cells[XcelRow, XcelCol];

From any other excel elements like value, formula, address I use, I am also unable to get the name of the named range.

Upvotes: 0

Views: 1599

Answers (1)

Rahul Tripathi
Rahul Tripathi

Reputation: 172618

If you want to get a range of cells you may try like this:

Excel.Worksheet worksheet = workbook.ActiveSheet;
Excel.Range x = (Excel.Range) worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[10,10]);

And if you are looking to get the names then try like this:

Workbook.Sheet.Names("Test").RefersToRange.Value;

Upvotes: 1

Related Questions