Applying Animations to Shapes in Office 2010
Programmatically Working with Shapes in Office 2010: Learn how to manipulate the color format property of a shape in a Microsoft PowerPoint 2010 presentation.
Last modified: April 22, 2011
Applies to: Excel 2010 | Office 2010 | PowerPoint 2010 | Word 2010
Published: April 2011
Provided by: Frank Rice, Microsoft Corporation
Microsoft Office 2010 includes the ability to work with many kinds of art shapes. Some examples of shapes include lines, connectors, basic shapes, flowchart elements, stars and banners, and callouts. It is easy to apply animations to shapes. In this topic, you programmatically create some simple shapes and then apply animations to them. 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
Start PowerPoint 2010.
On the Developer tab, click Visual Basic. This opens the Visual Basic Editor.
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.
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. This code creates a shape and adds three animations to it, picks up the animation, and then applies the animation to two other shapes.
To add code to the Visual Basic Editor
In the Projects pane, click Module1.
Paste or type the following Microsoft Visual Basic for Applications (VBA) code into the module window.
Sub TestPickupAnimation() With ActivePresentation.Slides(1) Dim shp1, shp2, shp3 As Shape ' Create the initial shape and apply the animations. Set shp1 = .Shapes.AddShape(msoShape12pointStar, 20, 20, 100, 100) .TimeLine.MainSequence.AddEffect shp1, msoAnimEffectFadedSwivel, , msoAnimTriggerAfterPrevious .TimeLine.MainSequence.AddEffect shp1, msoAnimEffectPathBounceRight, , msoAnimTriggerAfterPrevious .TimeLine.MainSequence.AddEffect shp1, msoAnimEffectSpin, , msoAnimTriggerAfterPrevious ' Now create a second shape, and apply the same animation to it: shp1.PickupAnimation Set shp2 = .Shapes.AddShape(msoShapeHexagon, 100, 20, 100, 100) shp2.ApplyAnimation ' And one more: Set shp3 = .Shapes.AddShape(msoShapeCloud, 180, 20, 100, 100) shp3.ApplyAnimation End With End Sub
The PickupAnimation method places the animation information for a specific shape in a "holding area". The ApplyAnimation method enables you to apply the animation to a specific shape.