The Baker’s Dozen: 13 Productivity Tips for Generating PowerPoint Presentations This installment of “The Baker’s Dozen” finds the Baker expanding from pastries to eye candy: generating PowerPoint output. Many power users build presentations using data from Excel or other data sources. This article shows how to automate Microsoft PowerPoint 2003 from within a Visual Studio 2005 application. The article presents a class called GenPPT, which creates several different types of slides, including slides that integrate tables and charts. GenPPT is written in Visual Basic 2005, and the demo program that calls it is written in C#: this demonstrates using multiple .NET languages in a solution. Beginning with the End in Mind Several times in the last year, I’ve seen online questions about generating PowerPoint output automatically. Just like Microsoft Word and Microsoft Excel, PowerPoint contains a rich object model that a developer can utilize to generate attractive and appealing slideshows. So I decided to devote a Baker’s Dozen article to the topic of PowerPoint automation within Visual Studio 2005. | " | If you’re not sure how to perform a specific programming task in PowerPoint (or any Microsoft Office Product), create a macro and then perform the task. In most instances, the code in the VBA macro will show you the way.
| " |
This article presents a Visual Basic 2005 class that aids a developer with the following PowerPoint tasks: - General structure of PPTGen
- Creating an instance of PowerPoint
- Starting a new presentation with a template and a title page
- Creating a text-only slide with a title and a set of bullet points
- Baker’s Dozen Spotlight: building an Excel table that you can use to generate a PowerPoint table or a Chart object
- Creating a slide that displays an Excel table
- Building an Excel table that you can use as a source for an Excel chart object
- Customizing the display of an Excel chart object
- Creating a slide that displays both a table and a pie chart
- Creating a slide that displays a line chart
- Setting animations and slide transitions
- Defining page footer information
- Saving and displaying the presentation
Deciding on an example to illustrate a set of classes can be an interesting thought process. Initially I was going to use data from the Northwind database-but since it’s near the end of the football season (I’m writing this in mid-December), I decided to have some fun with it. I am a big Kansas City Chiefs fan, and it was only a few years ago that KC started the season 9-0 and had Super Bowl hopes. Of course, it didn’t turn out that way, but I decided to build a PowerPoint presentation on their 2003 season. Here we go! Tip 1: General Information for GenPPT GenPPT is a DLL, written in Visual Basic 2005. It contains COM references to the Microsoft Excel 11.0 and Microsoft PowerPoint 11.0 Object Libraries. It also contains COM references to Microsoft Core Office Library and Visual Basic for Application Extensibility: Visual Studio 2005 automatically adds these references when you add the PowerPoint and Excel object libraries. To add these libraries manually, bring up the Solution Explorer window (from the View menu choose Solution Explorer), navigate to the References folder, right-click and choose “Add Reference.” From the Add Reference window, click the COM tab and scroll down to the Microsoft Excel and Microsoft PowerPoint Object Libraries to select them. GenPPT contains one class file, PowerPointTools.VB. The class contains the following import statements to access the PowerPoint and Excel object models. Imports PowerPoint = Microsoft.Office.Interop.PowerPoint
Imports Graph = Microsoft.Office.Interop.Graph Imports Excel = Microsoft.Office.Interop.Excel Imports System.Drawing
Table 1 and Table 2 list all the public properties and methods of GenPPT. GenPPT also contains a few support methods for common tasks (Table 3). Tip 2: Creating an Instance of PowerPoint Kicking off GenPPT is easy-add a reference to PowerPointTools.DLL to your project and then run the following code. // Create instance of GenPPT PowerPointTools oPPT = new PowerPointTools(); oPPT.LaunchPPT();
The code for LaunchPPT creates new instances for PowerPoint 2003 and Excel. Note that the method utilizes the object property references to oPPTApp and oExcel, which other methods in the class will use. Public Sub LaunchPPT() Me.oPPTApp = New PowerPoint.Application Me.oPPTApp.Visible = False
Me.oExcel = New Excel.Application Me.oExcel.Visible = False
Me.SlideNumber = 0 End Sub
| & | | 
By: Kevin S Goff
Kevin S. Goff, a Microsoft MVP award recipient for 2007, is the founder and principal consultant of Common Ground Solutions, a consulting group that provides custom Web and desktop software solutions in .NET, VFP, SQL Server, and Crystal Reports. Kevin is the author of Pro VS 2005 Reporting using SQL Server and Crystal Reports, published by Apress. Kevin has been building software applications since 1988. He has received several awards from the U.S. Department of Agriculture for systems automation. He has also received special citations from Fortune 500 Companies for solutions that yielded six-figure returns on investment. He has worked in such industries as insurance, accounting, public health, real estate, publishing, advertising, manufacturing, finance, consumer packaged goods, and trade promotion. In addition, Kevin provides many forms of custom training. Contact Kevin at kgoff@commongroundsolutions.net
kgoff@commongroundsolutions.net | Fast Facts | | The GenPPT class contains a set of starter productivity methods for building PowerPoint slides from a .NET application. GenPPT assists a developer in building slides with multiple levels of bullet points, tables, and charts. | |
|