pzajk
Sep 21, 2023Brass Contributor
Status:
New
[PowerPoint javascript API] Add event listener for objects removed from slide
With the current version of Office js API it is not possible to track whether an object was removed from the slide. Would it be possible to have an event listener triggered when object is removed ...
FromTheArctic
Mar 15, 2024Copper Contributor
Although there is nothing in office.js that supports this directly, you should be able to achieve what you need by using
Office.context.document.addHandlerAsync(
Office.EventType.DocumentSelectionChanged
This allows you to run a function every time a selection change happens. If your add-in keeps track of all shapes (using
const slide = context.presentation.slides.getItemAt(<currently selected slide index);
const shapes = slide.shapes;
// Load all the shapes in the collection without loading their properties.
shapes.load("items/Name");
) you can detect a removal by comparing to the previous set of shapes. As part of that comparison you can then get the data of the removed shape (for example its Name in the example above)