Using Visual Studio 2005 Tools for the Office System SE to Create PowerPoint Add-Ins
Applies to: 2007 Microsoft Office System, Microsoft Office PowerPoint 2007, Visual Studio 2005, Visual Studio 2005 Tools for Office Second Edition
Ken Getz, MCW Technologies, LLC
May 2007
Microsoft Visual Studio 2005 Tools for Office Second Edition (VSTO 2005 SE) makes it easy to create application-level add-ins for Office 2007 products, including Microsoft Office PowerPoint 2007. You can use application-level add-ins to extend the built-in functionality in the host application, or to add support for domain-specific functionality. In this article, you learn to create a simple add-in that prints the current presentation using pre-configured settings instead of configuring the settings each time you print. If you often print a presentation in pure black and white, two slides per page, you might appreciate the simplicity and convenience of creating and using this add-in.
In this demonstration, you customize the Office Fluent Ribbon by adding a button to the Add-Ins tab in Office PowerPoint 2007. Clicking the button prints the current presentation with two slides per page, in pure black and white format. To create the Office Fluent Ribbon customization
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="OnLoad"> <ribbon> <tabs> <tab id="CommonTasksAddIns" label="Common Tasks"> <group id="Group1" label="My Stuff" visible="true"> <button id="SetPrint" label="Print 2" size="large" screentip ="Print two framed slides per page" onAction="PrintButtonClick" imageMso="FilePrintQuick"/> </group> </tab> </tabs> </ribbon> </customUI> The add-in must load the Ribbon1.xml file at runtime. By default, the template includes a procedure that handles this in a standard way. It's far easier to load the Ribbon1.xml file as a resource. To load the Ribbon1.xml file as a resource
At runtime, the add-in calls a special procedure to load a copy of your Office Fluent Ribbon customization, and you must add that procedure. The add-in template includes the procedure—you must simply uncomment it. To add the ThisAddIn procedure
To add a using statement
using PowerPoint=Microsoft.Office.Interop.PowerPoint;
To modify GetCustomUI
To add a callback procedure
To verify the new buttons and replace PrintButtonClick
public void PrintButtonClick(Office.IRibbonControl control) { // Retrieve a reference to the active presentation: PowerPoint.Presentation presentation = Globals.ThisAddIn.Application.ActivePresentation; // Retrieve a reference to the PowerPoint printing options: PowerPoint.PrintOptions options = presentation.PrintOptions; // Set the various printing options: options.OutputType = PowerPoint.PpPrintOutputType.ppPrintOutputTwoSlideHandouts; options.FrameSlides = Microsoft.Office.Core.MsoTriState.msoCTrue; options.PrintColorType = PowerPoint.PpPrintColorType.ppPrintPureBlackAndWhite; options.PrintInBackground = Microsoft.Office.Core.MsoTriState.msoTrue; // Print the presentation: presentation.PrintOut( 1,presentation.Slides.Count,String.Empty, 1,Microsoft.Office.Core.MsoTriState.msoFalse); } Save and run the project. In the running instance of PowerPoint 2007, create a few slides, and add some text to the slides. Select the Common Tasks tab, and click the Print 2 button. Verify that the presentation prints to the default printer, two slides per page, in pure black and white. Close PowerPoint when you are done, returning to Visual Studio.
The PowerPoint object model is richer than this one simple add-in demonstrates. For more information about the PowerPoint object model in code, see the PowerPoint Help documentation and the documentation listed in the Explore It section. |
Video Length: 00:09:23 File Size: 08.57 MB WMV
|
Note:
