Microsoft Office Tutorials and References
In Depth Information
Set the presentation theme
Set the presentation theme
Presentation themes, colors, and properties can be changed using C# programming
with the support of VSTO 3.0. Zack has another task at hand—his manager wants
all of the PowerPoint applications that have a default white background theme to
be changed to some colorful theme. For such a scenario, the ApplyTheme method
is available in the PowerPoint.Presentation object to apply any theme to the
entire presentation.
Let's learn how to apply themes using VSTO programming, by examining the
following procedure.
Open Visual Studio 2008 and create a new solution, as explained earlier. In the
ThisAddIn.cs file, write the following program to set a theme for presentation in
Microsoft Office PowerPoint 2007:
// PowerPoint application object instance
PowerPoint.Application PacktPowerPointApplication;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
// Get access to the instance of current application
PacktPowerPointApplication = this.Application;
// Registering the AfterNewPresentation event of the PowerPoint
PacktPowerPointApplication.AfterNewPresentation +=
new PowerPoint.EApplication_
AfterNewPresentationEventHandler(
PacktPowerPointApplication_AfterNewPresentation);
}
// AfterNewPresentation event of PowerPoint presentation
private void PacktPowerPointApplication_AfterNewPresentation(
PowerPoint.Presentation PacktPresentation)
{
// Call the custom function to apply theme
Packt_ApplyTheme(PacktPresentation);
}
// Custom function to apply theme
private void Packt_ApplyTheme(PowerPoint.Presentation
PacktPresentationAdd)
{
// Locating the path where theme files are located in your system
// .thmx are the theme file format for Microsoft Office PowerPoint
PacktPresentationAdd.ApplyTheme(@"C:\Program Files\Microsoft
Office\Document Themes 12\Foundry.thmx");
}
Adding and executing the preceding code, results in a theme as shown in the
following screenshot:
 
Search JabSto ::




Custom Search