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