PowerPoint 2010 animation set via VBA fails to work properly after two sequences RRS feed

  • Question

  • I’m trying to create animations in PowerPoint 2010 using VBA but I’m running into a problem. I have large amounts of data in SQL Server that I’m churning through and summarizing and wanted to use this data to create shapes and associated animations based on the data. I’m doing this through code because the data will change fairly frequently and I don’t want to have to recreate the animations manually. The animations are fairly basic, I’m starting with one color and morphing to another color. The animation type is called “Fill Color” on the animation pane. So one shape might start with red as a background color and move to blue.
    The problem I am having is that if I create more than two animation sequences, the third (or greater) animation sequence does not end with the color I’ve set for it. The first two animations work fine. It doesn’t seem to matter if all the animations are for one shape or if the animations are set for different individual shapes (such as three ovals). If I create a third, fourth or fifth shape and add an animation to each of them they will not go to the final color I’ve set for them, only the first two will work correctly. The others will animate and start with the correct color but will morph to a color I didn’t specify. If I create a new slide and start all over it has the same issue.
    Below is example code. The final code will be a bit more complex since the data resides in a database and the colors will depend on what data has been retrieved. This code creates three “fill color” animations and assigns them to the first shape in the shapes collection on slide 3. They should all go from green to blue, but only the first 2 will do this.
        Dim item As Shape
        Dim effNew As Effect
        Set item = ActivePresentation.Slides(3).Shapes(1)
        For x = 1 To 3
            Set effNew = ActivePresentation.Slides(3).TimeLine.MainSequence.AddEffect(Shape:=item, effectId:=msoAnimEffectChangeFillColor)
            effNew.Behaviors.item(1).ColorEffect.From.RGB = RGB(0, 255, 0)
            effNew.Behaviors.item(1).ColorEffect.To.RGB = RGB(0, 0, 255)
    Here is somewhat similar code that also fails in the same way. This code loops through the MainSequence collection of existing animations and sets the fill colors using different properties than the code above. 
        Dim item As Effect
        For x = 1 To ActivePresentation.Slides(2).TimeLine.MainSequence.Count
            Set item = ActivePresentation.Slides(2).TimeLine.MainSequence.item(x)
            item.Shape.Fill.ForeColor.RGB = RGB(0, 255, 0)
            item.EffectParameters.Color2.RGB = RGB(0, 0, 255)
    Any help would be appreciated as my first presentation is quickly approaching.
    Friday, January 27, 2012 5:57 AM

All replies

  • Just tried this myself using PowerPoint 2010 (on Windows 7). First I created a shape (oval) on slide 1. I modified the code to reference this slide instead of 3. I then ran the code in the immediate window. I guess you can run it from the macro dialog too. Then I returned to the slide and viewed the animation pane and saw 3 "sequences". When I played the animations the first 2 work the 3rd one doesn't animate to the correct color. It doesn't seem obvious to me why it doesn't work, maybe it's a bug in PowerPoint?

    Hopefully someone else knows the answer?

    Tuesday, January 31, 2012 9:56 PM