I would like to change the scope of a named range programmatically.
Example: Range (“Test”) in designer file has the range $5: $9.
During runtime I want to change the Range to $5: $15.
At the moment I try to do the following, but this doesn’t work: I simply create a new range with the desired properties by means of .Cells.CreateRange and then assign the name of the original range to it. There doesn’t occur an error, but the result is rather odd: The new range is “shifted down” by the number of lines that the new range contains.
In my example above the new range “Test” would therefore start at row 15 and end at row 25.
Is there another way to achieve this?? An if there is no possibility yet available, would it be possible to implement it? (I think for example of a method InsertRows available in the range object…)
Which version are you using? Have you checked our latest hotfix?
Excel excel = new Excel();
excel.Open("d:\\range.xls"); // file with range $5: $9
Range range = excel.Worksheets.Cells.CreateRange(4, 11, false);
range.Name = "Test";
excel.Save("book1.xls", SaveType.OpenInExcel, FileFormatType.Default, this.Response);
It works fine with the above sample code.
If the problem still exists in your place, could you zip your designer file and related code, then send them to me? Thanks.
I tried the hotfix and the CreateRange-Method with firstIndex, number and bool as parameters worked fine.
The CreateRange-Method with parameters firstRow, firstColumn, rowNumber, columnNumber still shows the same strange behaviour.
It all works fine in my machine. Could you send your designer file and test code to me? Thank you.