I tried to read range from named item in workbook, but getting an error:
This operation is not permitted for the current object.
First of all created name range(using add()
method on names object).
Excel.run(function (ctx) {
var sheet = ctx.workbook.names.add("MyRange", "Sheet1!A1B2");
return ctx.sync().then(function () {
console.log("range name added");
}).catch(function (e) {
console.log("Error Message is -> " + e.message);
})
});
Till now code works very fine. Now I want to read a range for an existing named range. So I made some changes to my code:
Excel.run(function (ctx) {
var sheet = ctx.workbook.names.add("MyRange", "Sheet1!A1B2");
return ctx.sync().then(function () {
console.log("range name added");
var range = ctx.workbook.names.getItem("MyRange").getRange();
range.load("address");
return ctx.sync().then(function () {
console.log(range.address);
});
});
}).catch(function (e) {
console.log("Error Message is -> " + e.message);
});
When I try to run this code I get the error above. I used same method as mentioned in Office.js API.