Get the current selection on PowerPoint Add-In

Samuel Monteiro 1 Reputation point
2022-02-04T19:46:07.62+00:00

I'm developing a Add-in for PowerPoint that inserts images in the document.

I'm currently able to insert the image, but what I'm not able to do is to replace a current selected image.
So, for example, imagine that

  1. The user added an image available on the Add-in, inside an empty slide
  2. He then selected this image and wants to replace it with another one also available on the Add-in
  3. He clicks/selects the slide image, and then clicks on the image inside the Add-in that he wants to replace.

But I'm not able to get his selection with the Office API.

Can someone help me?

My current code is like this:

  const insertFile = (binaryStr: string) => {
    const dataOptions = {
      coercionType: Office.CoercionType.Image,
    };

    Office.context.document.setSelectedDataAsync(binaryStr, dataOptions, (result) => {
      if (result.status === Office.AsyncResultStatus.Failed) {
        console.error(result.error.message);
      }
    });
  };
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
982 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,898 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.