Export (0) Print
Expand All

Controlling Click Behavior for Animations in Office 2010

Office 2010

Office Quick Note banner

Programmatically Working with Shapes in Office 2010: Learn how to control the click behavior for animations 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

In this topic, you programmatically change the click behavior in a Microsoft PowerPoint 2010 presentation. 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 SlideShowClicks()
        If SlideShowWindows.Count = 0 Then
            Exit Sub
        End If
       
        Dim sswView As SlideShowView
        Set sswView = SlideShowWindows(1).View
       
        ' This should return true, because the first animation occurs
        ' without requiring user input:
        Debug.Print "First animation is automatic: " & sswView.FirstAnimationIsAutomatic
       
        Debug.Print "Click animations: " & sswView.GetClickCount
    
        'Get the current index of click animations on the slide.
        Debug.Print "Current click position (before GotoClick):  " & sswView.GetClickIndex
    
        'Jump to the 2nd mouse click.
        sswView.GotoClick 2
       
        'Get the current index of click animations on the slide.
        Debug.Print "Current click position (after GotoClick):  " & sswView.GetClickIndex
       
    End Sub
    
    Sub CreateShapesAndAnimations()
        Dim sld As Slide
        Set sld = ActivePresentation.Slides(1)
        Dim shp As Shape
       
        ' Create a shape and add it to the timeline.
        Set shp = sld.Shapes.AddShape(msoShapeCloud, 10, 10, 200, 200)
        shp.Fill.ForeColor.RGB = vbRed
        sld.TimeLine.MainSequence.AddEffect shp, effectId:=msoAnimEffectBoomerang, trigger:=msoAnimTriggerWithPrevious
           
        ' Repeat for a second shape.
        Set shp = sld.Shapes.AddShape(msoShape8pointStar, 150, 240, 200, 200)
        shp.Fill.PresetGradient msoGradientHorizontal, 1, msoGradientDaybreak
        sld.TimeLine.MainSequence.AddEffect shp, effectId:=msoAnimEffectAscend
       
        ' Add a third shape.
        Set shp = sld.Shapes.AddShape(msoShapeDecagon, 500, 10, 200, 200)
        shp.Fill.Solid
        shp.Fill.ForeColor.ObjectThemeColor = msoThemeColorAccent4
        sld.TimeLine.MainSequence.AddEffect shp, effectId:=msoAnimEffectDescend
       
        ' Add a fourth shape.
        Set shp = sld.Shapes.AddShape(msoShapeCan, 500, 240, 200, 200)
        shp.Fill.Solid
        shp.Fill.ForeColor.ObjectThemeColor = msoThemeColorAccent2
        sld.TimeLine.MainSequence.AddEffect shp, effectId:=msoAnimEffectCenterRevolve
    End Sub
    
    

In this task, you run the code and observe the results.

To run the code

  1. Place the cursor in the CreateShapesAndAnimations procedure and then press F5.

  2. Switch to PowerPoint, and run the presentation. Slowly click on the first slide three times to view the complete set of animations, noting that the first animation occurs before you click.

  3. Press Esc to reset the presentation and then rerun the slide show but do not click the mouse.

  4. After the first animation occurs, switch back to the Visual Basic Editor, place the cursor in the SlideShowClicks procedure, and then press F5. Note the results in the Immediate window. The code moves the animation to click number two.

  5. Switch back to the running presentation, and you'll see the animation immediately progresses as if you had clicked twice.

  6. Click the presentation one time to show the final shape.

Show:
© 2014 Microsoft