1

I'm developing an Office Add-In for Power Point. An example from the documentation about how to change slide is:

function goToSlideByIndex() {
    var goToNext = Office.Index.Next;

    Office.context.document.goToByIdAsync(goToNext, Office.GoToType.Index, function (asyncResult) {
        if (asyncResult.status == "failed") {
            showMessage("Action failed with error: " + asyncResult.error.message);
        }
        else {
            showMessage("Navigation successful");
        }
    });
}

However, with this API I want to get the current slide id. Seems like there is no such a function in the Office-JS API.

How do I get this information?

1 Answer 1

2

We can get the current index of active slide via using the document.getSelectedDataAsync method. Here is an example for your reference:

Office.context.document.getSelectedDataAsync(Office.CoercionType.SlideRange, function (asyncResult) {
            if (asyncResult.status == "failed") {
                app.showNotification("Action failed with error: " + asyncResult.error.message);
            }
            else {

                app.showNotification(asyncResult.value.slides[0].index);
            }
        });

Note, the function is an asynchronous method. The result maybe not expected when you change the slide quickly after you call this method

Sign up to request clarification or add additional context in comments.

3 Comments

I saw this in the doc, but document.getSelectedDataAsync should return the current selected slides right?
document.getSelectedDataAsync return the selected data. And we also can use this method to get the index of current selected slides.
How about in slideshow mode? This method doesn't seem to be working in slideshow mode.

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.