3

I'm working on a Office add-in for PowerPoint. This is a modern 'add-in' for the Office store, not the old style add-in.

Is there a way to be notified when the active slide is changed?

My scenario is that I want to do something in my add-in code when the slide changes as a presentation is being given.

My app could be a content or task pane app at this stage.

Martin Kearn
  • 2,313
  • 1
  • 21
  • 35

1 Answers1

4

There is no direct way to do this. The Office JS library does not have an event for slide transitions in PowerPoint.

However, there is a hacky way to do this which involves refreshing the web app on a periodic basis and using getSelectedDataAsync with the CoercionType of SlideRange. This gives you the full range of slides in the document and from that you can get the index of the current slide. You could store that index in a setting and check if it changes if it does you have your event.

Here is the basic code (refreshes every 1.5 seconds)

//Automatically refresh
window.setInterval(function () {
//get the current slide
Office.context.document.getSelectedDataAsync(Office.CoercionType.SlideRange, function (r) {

      // null check
      if (!r || !r.value || !r.value.slides) {
        return;
      }

    //get current slides index
    currentSlide = r.value.slides[0].index;

    //get stored setting for current slide
    var storedSlideIndex = Office.context.document.settings.get("CurrentSlide");
    //check if current slide and stored setting are the same
    if (currentSlide != storedSlideIndex) {
        //the slide changed - do something
        //update the stored setting for current slide
        Office.context.document.settings.set("CurrentSlide", currentSlide);
        Office.context.document.settings.saveAsync(function (asyncResult) { });
    }

});

}, 1500);
JsAndDotNet
  • 16,260
  • 18
  • 100
  • 123
Martin Beeby
  • 4,523
  • 1
  • 26
  • 20
  • 2
    Hi! Is there any plans for adding callback support for slide change event? Looks like Martin isn't the only one who needs this ))) – Victor Suzdalev Mar 30 '16 at 08:48
  • Since this is 3 years ago, has this slide change event been added? – Jacob Apr 05 '18 at 09:31
  • I'm desperately trying to find a solution, this one could have done the trick but it actually works only in "edit" mode, once in "read" mode I get errors in the console. Is there a workaround working once slideshow began? Edit: my bad, it's working perfectly **except** when you reduce the slideshow controller to try and watch the debug console behind, it works fine in other situations. – naholyr Feb 26 '19 at 17:25
  • Great, glad that this answer is still providing some value. – Martin Beeby Feb 26 '19 at 17:38
  • As PowerPoint desktop uses Internet Explorer as an internal browser, `getSelectedDataAsync` fires memory leak. Any alternative solutions? – robdev91 Apr 13 '21 at 15:31