0

The NamedItem object has a getRange() function, but I get the error message

"This operation is not permitted for the current object"

When I use it on a NamedItem which has two noncontiguous ranges. Is there any way to get the ranges from a multi-area range name in OfficeJS?

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45

1 Answers1

1

The NamedItem.getRange() method is only permitted for named items that refer to a single range. There is not yet a method to retrieve multiple ranges for a named item. A workaround for you to consider is to parse the value of the NamedItem.formula property. For a named item that refer to multiple ranges it will look something like this: "=Sheet1!$F$9:$G$14,Sheet1!$K$15:$N$21,Sheet1!$P$7:$S$11".

If you ignore the first character and split the rest of the string on the comma (,), you will get a list of addresses and you can then split each of these on the exclamation point (!) to get the sheet name and an address that you can then pass to Workbook.worksheets.getItem(sheetName) and Worksheet.getRange(address).