0

I am developing a PowerPoint add-in wherein there is a functionality of adding a slide using the base64 string and the method insertSlidesFromBase64. Below is the code for the same:

await PowerPoint.run(async (context) => { 

                    context.presentation.insertSlidesFromBase64(pptContent, { 

                        targetSlideId: `${selectedSlideID}#`, 

                        formatting: PowerPoint.InsertSlideFormatting.useDestinationTheme, 

                    }); 

                    await context.sync(); 

});

Here "selectedSlideID" is the unique id of the slide after which this slide needs to be inserted. When I am inserting, say, 3 slides using this method and then press undo button (or Ctrl +Z) all 3 slides disappear together. However, the expectation is that if we are inserting 3 slides then these are 3 separate actions and an undo command should remove only the last inserted slide. This is happening even if the Autosave feature is ON and also if we save the file where the slides are being inserted. Can you tell me why it is happening and if there is a fix for it?

4
  • It's likely working as designed. I don't use javascript to automate PPT, but this is how it's worked with VBA automation code pretty much forever. You can run insanely complex macros that affect every slide in a big presentation; CTRL+Z/Undo will undo everything. Commented Jul 1, 2024 at 14:34
  • 1
    I think SteveRindsberg is right that this is expected behavior. But maybe the rule is that undo will reverse everything since the previous call of context.sync. Your code shows only inserting one slide so it's difficult to see exactly what you mean by "inserting 3 slides". But try to code the insertions so that there is a context.sync between each of them and then see how undo behaves after they are all inserted. Commented Jul 4, 2024 at 0:26
  • @RickKirkham: Actually I am calling this method in a loop for different slide ids. So, the context.sync() is already in place for each slide. Commented Jul 5, 2024 at 5:51
  • Well having a context.sync in a loop is a bad practice anyway. See learn.microsoft.com/en-us/office/dev/add-ins/concepts/… Why don't you fix that and maybe the undo problem will get fixed along with it. Commented Jul 6, 2024 at 4:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.