How to program a PowerPoint custom object like Thinkcell objects?

140 Views Asked by At

I am very new to PowerPoint add-on development so please bear with me.

There are many objects that can be inserted into a PowerPoint slide, such as text box, shape, chart, etc. Is there a way to build my own custom object with custom properties and functionalities? For example, with the Thinkcell add-on, you can insert a Thinkcell chart object, connect it to Excel workbook, edit it, and show it. To the best of my understanding, this is a kind of custom object built into the Thinkcell add-on.

How can I build a custom object like this?

I have checked some tutorials on building a PowerPoint add-on with VBA, VSTO, and Javascript. To the best of my understanding, these technologies allow users to build some user interfaces to interact and modify the PowerPoint slides, such as creating and modifying elements in the slides. However, I don't see examples of creating a custom object using these technologies. Thus I am very curious about how add-ons create their custom element.

Thanks!

2

There are 2 best solutions below

2
On

First, you will need to install the necessary npm packages and set up the development environment.

For example, you can use the following command to install the Office.js library:

npm install @microsoft/office-js

Then, you can use the following code to create a custom object in a PowerPoint add-in:

Office.initialize = function () {
  // Create a new shape on the active slide
  var shape = PowerPoint.createShape("MyCustomObject", Office.MsoAutoShapeType.msoShapeRectangle, 50, 50, 100, 100);

  // Add a custom property to the shape
  shape.customProperties.add("dataSource", "Excel workbook");

  // Define a function to be called when the user clicks on the shape
  shape.click = function () {
    // Open the Excel workbook and display the data
    Office.context.ui.displayDialogAsync("https://example.com/excel-workbook", {height: 50, width: 50});
  };
};
 
0
On

Here is how you might accomplish this using VBA:

Sub ChangeObjectColor()
Dim obj As Shape

' Get a reference to the custom object
Set obj = ActivePresentation.Slides(1).Shapes("MyObject")

' Check the value of the FillColor property
If obj.FillColor = "red" Then
' Set the fill color of the object to red
obj.Fill.ForeColor.RGB = RGB(255, 0, 0)
ElseIf obj.FillColor = "green" Then
' Set the fill color of the object to green
obj.Fill.ForeColor.RGB = RGB(0, 255, 0)
End If
End Sub