Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / July 2006

Tip: Looking for answers? Try searching our database.

How do you Define a named range in excel using C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tim - 18 Jul 2006 15:47 GMT
I am trying to define a named range in excel through automation.

This is the VBA code from a macro that does what I want.  I'm trying to

define the name range so I can use a ADO connection later to insert
data.

Range("A1:E1").Select
   ActiveWorkbook.Names.Add Name:="MyTable",
RefersToR1C1:="=Sheet1!R1C1:R1C5"

This is about as close as i could figure it out.  It's clearly not
right any surgestions ?

object m_objOpt = System.Reflection.Missing.Value;
m_objExcel = new Excel.Application();
m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;
m_objBook = (Excel._Workbook)(m_objBooks.Add(m_objOpt));

m_objBook.Names.Add("MyTable","=Sheet1!R1C1:R1C5" , true, m_objOpt,
m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt);

not sure if i pasted enough of the code for you to see what I'm trying
to do.

Thanks
Cindy M  -WordMVP- - 26 Jul 2006 14:38 GMT
Hi Tim,

No idea if you're still working on this, but...

Take a close look at the arguments for the Names.Add method. There's a
"RefersTo" and a "ReferstoR1C1". You've put the name information for an
R1C1 reference in the argument for "RefersTo". you'd have to put it in
the argument for "RefersToR1C1" (second to last).

> I am trying to define a named range in excel through automation.
>  
[quoted text clipped - 25 lines]
> not sure if i pasted enough of the code for you to see what I'm trying
> to do.

   -- Cindy

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.