RE Define Named Range.

G

Guest

I need to programmatically redefine a named range (normally created On the
Insert menu, point to Name, and then click Define. Type the name e.g.
MyTable, select the range and then click OK.) in an excel file.
I need to change the range from e.g. A1:D18 to A1:D1.

How can this be done in C#? If you don't know C#, VB is ok too.
 
G

Guest

I usually just do something like this in VBA

ActiveWorkbook.Names.Add "SampleName", "=$A$1:$D$1"


if SampleName doesn't exist yet, it creates it. If it already exists, then
it gets overwritten with the new reference.
 
G

Guest

Sorry, I'm a VB guy.

FWIW, this worked with VB.NET. I have the Excel 11 Object Library.


Imports Microsoft.Office.Interop

Module Module1
Sub Main()
Dim xlapp As New Excel.Application
Dim xlwb As Excel.Workbook
xlapp.Visible = True
xlwb = xlapp.Workbooks.Add
xlwb.Names.Add("SampleName", "=$A$1:$D$1")
End Sub
End Module
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top