Working with Properties of the ShadowFormat Class in Office 2010

Office 2010

Office Quick Note banner

Programmatically Working with Shapes in Office 2010: Learn how to work with the properties of the ShadowFormat class in Microsoft PowerPoint 2010.

Last modified: May 20, 2011

Applies to: Excel 2010 | Office 2010 | PowerPoint 2010 | VBA | Word 2010

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

You can enhance images or text by adding effects, such as shadows, size, reflections, soft edges, blur, and three-dimensional (3-D) rotations to them. In this topic, you programmatically add a shape in a Microsoft PowerPoint 2010 presentation. You then manipulate the size, blur, and rotation properties of the shape. 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 ShadowFormatDemo()
        ' Work with new ShadowFormat features.
       
        ' Create a blank slide.
        Dim sld As Slide
        Set sld = ActivePresentation.Slides.Add(2, ppLayoutBlank)
      
        ' Add a shape to the new slide.
        Dim shp As Shape
        Set shp = sld.Shapes.AddShape(msoShapeGear9, 100, 100, 200, 200)
      
        sld.Select
      
        With shp.Shadow
            ' Set values to demonstrate blur:
            .Size = 120
            .ForeColor.ObjectThemeColor = msoThemeColorAccent6
            .Transparency = 0.8
           
            .OffsetX = 20
            .OffsetY = 40
           
            ' Work with the Blur property, which indicates the
            ' amount of blur in the shadow, measured in points:
            .Blur = 1
            .Blur = 5
            .Blur = 10
           
            ' Now try varying the Size property, which measures the
            ' size as a percentage of the size of the shape, times 100:
            .Size = 100
            .Size = 120
            .Size = 140
            .Size = 160
            .Size = 180
        End With
       
        ' The RotateWithShape property is misleading:
        ' The shadow always rotates with the shape. The behavior
        ' is subtly different, depending on the shape and the
        ' offset of the shadow. Try it both ways to compare.
        ' You should see a different when stepping through
        ' these two versions of the code. When the property is true,
        ' it looks like the source of the light casting the shadow
        ' rotates with the shape. When false, it looks like the source
        ' of the light doesn't move.
        shp.Shadow.RotateWithShape = msoTrue
        shp.Rotation = 30
        shp.Rotation = 60
        shp.Rotation = 90
        shp.Rotation = 120
        shp.Rotation = 150
        shp.Rotation = 180
        shp.Rotation = 210
        shp.Rotation = 240
        shp.Rotation = 270
        shp.Rotation = 300
        shp.Rotation = 330
       
        shp.Shadow.RotateWithShape = msoFalse
        shp.Rotation = 30
        shp.Rotation = 60
        shp.Rotation = 90
        shp.Rotation = 120
        shp.Rotation = 150
        shp.Rotation = 180
        shp.Rotation = 210
        shp.Rotation = 240
        shp.Rotation = 270
        shp.Rotation = 300
        shp.Rotation = 330
    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 ShadowFormatDemo module and then press F8 to step through the code line-by-line and watch the results.

Show:
© 2014 Microsoft