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.