add-inoffice-addinspowerpoint-2013

Is there a slide transition event for PowerPoint add-in (apps)


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.


Solution

  • 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);