0

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

1
  • I tried your code in the online version, and it works ok. However, I have some other code which is running into the same problem. I have no idea why it is happening, and it is somewhat inconsistent.
    – mabarif
    Commented Nov 8, 2023 at 13:50

1 Answer 1

1

This is a Bug in Powerpoint Web

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.