How can we create a 'named range' that has its scope set to a worksheet? (as we can do this manually from Excel, I guess there is a way to this in code)
Setting a name using the 'Range.Name' property creates a workbook-scoped named range. I tried prefixing the range name with '<Sheet Name>!' as suggested here, but it doesn't work. The name doesn't get set at all that way.
Any idea as to how this can be done in C#?
Update (2013/05/16): Answer by shahkalpesh worked. The original code (in VS 2010) I used is:
using Excel = Microsoft.Office.Interop.Excel;
Excel.Worksheet ws = Globals.ThisAddIn.Application.ActiveSheet;
Excel.Range range = ws.Range[ws.Cells[x,y], ws.Cells[(x + height), (y + width)]];
range.Name = "MyName"; // MyName in workbook scope
The modified code that works is:
ws.Names.Add("MyName", range); // MyName in worksheet scope
Thanks, idssl.