Walkthrough: Creating Your First VSTO Add-in for PowerPoint
This walkthrough shows you how to create an VSTO Add-in for Microsoft Office PowerPoint. The features that you create in this kind of solution are available to the application itself, regardless of which presentations are open. For more information, see Office Solutions Development Overview (VSTO).
Applies to: The information in this topic applies to VSTO add-in projects for PowerPoint. For more information, see Features Available by Office Application and Project Type.
This walkthrough illustrates the following tasks:
Creating a PowerPoint VSTO Add-in project for PowerPoint.
Writing code that uses the object model of PowerPoint to add a text box to each new slide.
Building and running the project to test it.
Cleaning up the project so that the VSTO Add-in no longer runs automatically on your development computer.
Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Personalizing the IDE.
You need the following components to complete this walkthrough:
An edition of Visual Studio that includes the Microsoft Office developer tools. For more information, see Configuring a Computer to Develop Office Solutions.
Start Visual Studio.
On the File menu, point to New, and then click Project.
In the templates pane, expand Visual C# or Visual Basic, and then expand Office/SharePoint.
Under the expanded Office/SharePoint node, select the Office Add-ins node.
In the list of project templates, select a PowerPoint VSTO Add-in project.
In the Name box, type FirstPowerPointAddIn.
Visual Studio creates the FirstPowerPointAddIn project and opens the ThisAddIn code file in the editor.
Next, add code to the ThisAddIn code file. The new code uses the object model of PowerPoint to add a text box to each new slide. By default, the ThisAddIn code file contains the following generated code:
A partial definition of the
ThisAddInclass. This class provides an entry point for your code and provides access to the object model of PowerPoint. For more information, see Programming VSTO Add-Ins. The remainder of the
ThisAddInclass is defined in a hidden code file that you should not modify.
ThisAddIn_Shutdownevent handlers. These event handlers are called when PowerPoint loads and unloads your VSTO Add-in. Use these event handlers to initialize your VSTO Add-in when it is loaded, and to clean up resources used by your VSTO Add-in when it is unloaded. For more information, see Events in Office Projects.
In the ThisAddIn code file, add the following code to the
ThisAddInclass. This code defines an event handler for the E:Microsoft.Office.Interop.PowerPoint.EApplication_Event.PresentationNewSlide event of the T:Microsoft.Office.Interop.PowerPoint.Application object.
When the user adds a new slide to the active presentation, this event handler adds a text box to the top of the new slide, and it adds some text to the text box.
If you are using C#, add the following code to the
ThisAddIn_Startupevent handler. This code is required to connect the
Application_PresentationNewSlideevent handler with the E:Microsoft.Office.Interop.PowerPoint.EApplication_Event.PresentationNewSlide event.
To modify each new slide, the previous code examples use the following objects:
Applicationfield of the
Applicationfield returns an T:Microsoft.Office.Interop.PowerPoint.Application object, which represents the current instance of PowerPoint.
Sldparameter of the event handler for the E:Microsoft.Office.Interop.PowerPoint.EApplication_Event.PresentationNewSlide event. The
Sldparameter is a T:Microsoft.Office.Interop.PowerPoint.Slide object, which represents the new slide. For more information, see PowerPoint Solutions.
When you build and run the project, verify that the text box appears in new slides that you add to a presentation.
Press F5 to build and run your project.
When you build the project, the code is compiled into an assembly that is put in the build output folder for the project. Visual Studio also creates a set of registry entries that enable PowerPoint to discover and load the VSTO Add-in, and it configures the security settings on the development computer to enable the VSTO Add-in to run. For more information, see Building Office Solutions.
In PowerPoint, add a new slide to the active presentation.
Verify that the following text is added to a new text box at the top of the slide.
This text was added by using code.
When you finish developing a project, remove the VSTO Add-in assembly, registry entries, and security settings from your development computer. Otherwise, the VSTO Add-in will run every time you open PowerPoint on the development computer.
- In Visual Studio, on the Build menu, click Clean Solution.
Now that you have created a basic VSTO Add-in for PowerPoint, you can learn more about how to develop VSTO Add-ins from these topics:
General programming tasks that you can perform in VSTO Add-ins for PowerPoint. For more information, see Programming VSTO Add-Ins.
Using the object model of PowerPoint. For more information, see PowerPoint Solutions.
Customizing the UI of PowerPoint, for example, by adding a custom tab to the Ribbon or creating your own custom task pane. For more information, see Office UI Customization.
Building and debugging VSTO Add-ins for PowerPoint. For more information, see Building Office Solutions.
Deploying VSTO Add-ins for PowerPoint. For more information, see Deploying an Office Solution.