I am trying to build an add-in for MS PowerPoint so I decided to test an examples from the docs which is:
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/text/get-set-textrange.yaml
// Selects the first 10 characters of the selected shape.
await PowerPoint.run(async (context) => {
const shapes = context.presentation.getSelectedShapes();
const shapeCount = shapes.getCount();
await context.sync();
if (shapeCount.value !== 1) {
console.warn("You must select only one shape with text in it.");
return;
}
const shape = shapes.getItemAt(0);
const textFrame = shape.textFrame.load("textRange,hasText");
await context.sync();
if (textFrame.hasText != true) {
console.warn("You must select only one shape with text in it.");
return;
}
const textRange = textFrame.textRange;
textRange.load("text");
await context.sync();
if (textRange.text.length < 10) {
console.warn("You must select only one shape with at least 10 characters in it.");
return;
}
const textRange10 = textRange.getSubstring(0, 10);
textRange10.setSelected();
await context.sync();
});
when running the code on MS PowerPoint the line await context.sync();
which loads the textRange throws an exception:
exception RichApi.Error: GeneralException
I tried everything I can with no success, any help is appreciated
I came across a similar error, and decided to report it to Microsoft: https://github.com/OfficeDev/office-js/issues/3826
They agreed that this is a bug and are looking into it now.