excel - c#: programmatically create a "named range" in worksheet scope -


how can create 'named range' has scope set worksheet? (as can manually excel, guess there way in code)

setting name using 'range.name' property creates workbook-scoped named range. tried prefixing range name '<sheet name>!' suggested here, doesn't work. name doesn't set @ way.

any idea how can done in c#?

update (2013/05/16): answer shahkalpesh worked. original code (in vs 2010) 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 works is:

ws.names.add("myname", range); // myname in worksheet scope 

thanks, idssl.

assumptions:
sheet1 has cells a1:a4, want create named range

vba:

sheet1.names.add("tada", sheet1.range("a1:a4") 

i suppose identical in c# (except ; @ end) , passing empty arguments optional parameters.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -