Get the sheet name from the named range. Object name

I have:

Microsoft.Office.Interop.Excel.Workbook wb;
Microsoft.Office.Interop.Excel.Name name;

Is there a way to get the name of the worksheet that lists the named range in this book if I already got the name of the named object of the name and wb?

+5
source share
3 answers

Yes, use the Parent property to work on the hierarchy of objects:

ws = name.RefersToRange.Parent.name;
+12
source

Range.Worksheetis a self-documenting alternative Range.Parent:

Microsoft.Office.Interop.Excel.Worksheet ws = name.RefersToRange.Worksheet;
string wsName = ws.Name;

Or in one fell swoop:

string wsName = name.RefersToRange.Worksheet.Name;

:
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.name.referstorange.aspx
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.range.worksheet.aspx
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel._worksheet.name(v=office.15).aspx

+1
wb.Names(name).RefersToRange.Parent.Name
0

All Articles