Using the ApplyTheme and BackgroundStyle Properties in PowerPoint 2010

Office 2010

Office Quick Note banner

Working with Styles in Microsoft PowerPoint 2010: Learn how to work with background styles and themes in Microsoft PowerPoint 2010.

Last modified: May 20, 2011

Applies to: Office 2010 | PowerPoint 2010 | VBA

In this article
Add a Standard Module to a PowerPoint Presentation
Add the Code to the Visual Basic Editor
Test the Solution
Next Steps

Published:   June 2011

Provided by:    Frank Rice, Microsoft Corporation

Themes simplify the process of creating matching, professional-looking documents. Likewise, applying a specific background style can add variety to your Microsoft PowerPoint 2010 presentations. In this topic, you programmatically add a shape in a presentation. You then manipulate the theme and background properties of the shape by using the ApplyTheme method and the BackgroundStyle property. To complete this task, you must do the following:

In this task, you open a PowerPoint 2010 presentation, open the Visual Basic Editor, and then insert a standard module.

To add a standard module to a PowerPoint presentation

  1. Start PowerPoint 2010.

  2. On the Developer tab, click Visual Basic. This opens the Visual Basic Editor.

    Note Note

    If you do not see the Developer tab in PowerPoint 2010, click the File tab, and then click Options. In the categories pane, click Popular, select Show Developer tab in the Ribbon, and then click OK.

  3. On the Insert menu, click Module. This adds Module1 to the Projects pane on the left side of the Visual Basic Editor.

In this task, you add programming code to the Visual Basic Editor.

To add code to the Visual Basic Editor

  1. In the Projects pane, click Module1.

  2. Paste or type the following Microsoft Visual Basic for Applications (VBA) code into the module window.

    Sub TestBackgroundStyle()
        Dim sld As Slide
        Set sld = ActivePresentation.Slides(1)
        ' Modify this to match your own environment:
        Const themePath As String = "C:\Program Files (x86)\Microsoft Office\Document Themes 14\"
        Const themeName1 As String = themePath & "Angles.thmx"
        Const themeName2 As String = themePath & "Perspective.thmx"
        Const themeName3 As String = themePath & "Waveform.thmx"
        ActivePresentation.ApplyTheme themeName1
        CycleThroughStyles sld
        ActivePresentation.ApplyTheme themeName2
        CycleThroughStyles sld
        ActivePresentation.ApplyTheme themeName3
        CycleThroughStyles sld
    End Sub
    Private Sub CycleThroughStyles(sld As Slide)
        ' This exercise will only be meaningful if you single step through this code.
        ' Each style looks slightly different:
        sld.BackgroundStyle = msoBackgroundStylePreset1
        sld.BackgroundStyle = msoBackgroundStylePreset2
        sld.BackgroundStyle = msoBackgroundStylePreset3
        sld.BackgroundStyle = msoBackgroundStylePreset4
        sld.BackgroundStyle = msoBackgroundStylePreset5
        sld.BackgroundStyle = msoBackgroundStylePreset6
        sld.BackgroundStyle = msoBackgroundStylePreset7
        sld.BackgroundStyle = msoBackgroundStylePreset8
        sld.BackgroundStyle = msoBackgroundStylePreset9
        sld.BackgroundStyle = msoBackgroundStylePreset10
        sld.BackgroundStyle = msoBackgroundStylePreset11
        sld.BackgroundStyle = msoBackgroundStylePreset12
        ' Note that these options are not valid:
        ' sld.BackgroundStyle = msoBackgroundStyleMixed
        ' sld.BackgroundStyle = msoBackgroundStyleNotAPreset
    End Sub

In this task, you step through the code. The best way to see the code in action is to place the Visual Basic Editor and the PowerPoint screen side-by-side.

To run the code

  1. Drag the Visual Basic Editor to the right side of the screen.

  2. Next, drag the PowerPoint screen to the left side of the screen and adjust both screens until you can see clearly.

  3. Place your cursor in the TestBackgroundStyle module and then press F8 to step through the code line-by-line and watch the results.

© 2015 Microsoft