0

I am trying to create a PowerPoint Addin and would like to dynamically create and format a textbox on an active slide when a button is clicked. I have done a lot of research and debugging but I am not sure why my code is not creating the textbox. I am using PowerPoint JavaScript API on VS Code Here is my sample code

function createDynamicTextBox() {
// Get the active slide
Office.context.document.getSelectedDataAsync(Office.CoercionType.SlideRange, function (result) {
  if (result.status === Office.AsyncResultStatus.Succeeded) {
    // Get the first slide
    var slide = result.value.slides[0];

    // Create a text box
    var textBox = slide.shapes.addTextbox(Office.CoercionType.Text, 100, 100, 200, 50);

    // Set properties of the text box
    textBox.textFrame.textRange.text = "Dynamic Text Box";
    textBox.textFrame.textRange.font.size = 14;

    // You can further customize the properties as needed
  } else {
   console.error("Error getting selected data: " + result.error.message);
  }
});

The problem is with the shapes object which on debug returns 'undefined'. I am wondering whether it is possible to achieve what I would like.

1 Answer 1

0

It makes sense to call the await context.sync(); when you would like to apply your changes.

Be aware, there is an active issue with PowerPoint shapes, see Powerpoint ScriptLab Insert shape, line and text box sample does not work on web; works fine on desktop for more information.

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

Comments

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.