PPT animations

Add-in Express™ Support Service
That's what is more important than anything else

PPT animations
 
briannesbitt


Guest


I have 2 (hopefully quick) questions.

1) After calling AddEffect() on the slide.TimeLine.MainSequence I get back an Effect object. I try to set the effect.Timing.Duration value to 0.25f. When I view the duration of the animation in PowerPoint its always set to 0.5 seconds no matter what I set the Duration value to. I can then use the PowerPoint UI to set the duration to 0.25 seconds and of course that works. Any idea on how to set the duration?

2) Is there a way to run the animations preview programatically? (mimic clicking the Preview button in the Animations ribbon) ?

Thanks.
Posted 23 Nov, 2015 14:58:54 Top
Andrei Smolin


Add-in Express team


Posts: 18817
Joined: 2006-05-11
Hello Brian,

The VBA code below is a modified version of the code published at https://msdn.microsoft.com/en-us/library/office/ff744538.aspx:

Sub NewShapeAndEffect()
    Dim shpStar As Shape
    Dim sldOne As Slide
    Dim effNew As Effect

    Set sldOne = ActivePresentation.Slides(1)
    Set shpStar = sldOne.Shapes.AddShape(Type:=msoShape5pointStar, _
        Left:=150, Top:=72, Width:=400, Height:=400)
    
    Set effNew = sldOne.TimeLine.MainSequence.AddEffect(Shape:=shpStar, _
        EffectId:=msoAnimEffectStretchy, Trigger:=msoAnimTriggerAfterPrevious)

    With effNew
        With .Behaviors.Add(msoAnimTypeScale).ScaleEffect
            .FromX = 75
            .FromY = 75
            .ToX = 0
            .ToY = 0
        End With
        .Timing.Duration = 0.25
    End With
End Sub


Create a new presentation, press {Alt+F11} to open the VBA IDE. Choose menu Insert | Module and paste the code above into the code pane. Put the text cursor on any line of the method above and press {F5}. Now switch back to the presentation, select the 5-point star inserted by the method above and check the duration. It's 0.25 for me.


Andrei Smolin
Add-in Express Team Leader
Posted 24 Nov, 2015 06:53:24 Top
briannesbitt


Guest


That works for me too.

All I want though is:


Sub NewShapeAndEffect() 
    Dim shpStar As Shape 
    Dim sldOne As Slide 
    Dim effNew As Effect 
 
    Set sldOne = ActivePresentation.Slides(1) 
    Set shpStar = sldOne.Shapes.AddShape(Type:=msoShape5pointStar, _ 
        Left:=150, Top:=72, Width:=400, Height:=400) 
     
    Set effNew = sldOne.TimeLine.MainSequence.AddEffect(Shape:=shpStar, _ 
        EffectId:=msoAnimEffectFly, Trigger:=msoAnimTriggerAfterPrevious) 
 
    effNew.Timing.Duration = 0.25 
End Sub 


When I do this I get a fly-in effect that has a duration of 0.25 seconds.

When I do the equivalent from c# I get a fly-in effect that has a duration of 0.5 seconds no matter what I assign "effNew.Timing.Duration" to.
Posted 24 Nov, 2015 13:16:11 Top
briannesbitt


Guest


Ok... got it working....

Turns out this doesn't work..


Sub NewShapeAndEffect()
    Dim shpStar As Shape
    Dim sldOne As Slide
    Dim effNew As Effect
 
    Set sldOne = ActivePresentation.Slides(1)
    Set shpStar = sldOne.Shapes.AddShape(Type:=msoShape5pointStar, _
        Left:=150, Top:=72, Width:=400, Height:=400)
     
    Set effNew = sldOne.TimeLine.MainSequence.AddEffect(Shape:=shpStar, EffectId:=msoAnimEffectFly, Trigger:=msoAnimTriggerAfterPrevious)
 
    With effNew
        .Timing.Duration = 0.25
        .EffectParameters.Direction = MsoAnimDirection.msoAnimDirectionBottom
    End With
End Sub



.... but this does ....


Sub NewShapeAndEffect()
    Dim shpStar As Shape
    Dim sldOne As Slide
    Dim effNew As Effect
 
    Set sldOne = ActivePresentation.Slides(1)
    Set shpStar = sldOne.Shapes.AddShape(Type:=msoShape5pointStar, _
        Left:=150, Top:=72, Width:=400, Height:=400)
     
    Set effNew = sldOne.TimeLine.MainSequence.AddEffect(Shape:=shpStar, EffectId:=msoAnimEffectFly, Trigger:=msoAnimTriggerAfterPrevious)
 
    With effNew
        .EffectParameters.Direction = MsoAnimDirection.msoAnimDirectionBottom
        .Timing.Duration = 0.25
    End With
End Sub


Set the duration after you set a direction.

Thanks.



Any idea on how to trigger a preview to occur?
Posted 24 Nov, 2015 15:22:28 Top
Andrei Smolin


Add-in Express team


Posts: 18817
Joined: 2006-05-11
Hello Brian,

briannesbitt writes:
Set the duration after you set a direction.


Yes, there're others cases when the order of setting some properties matters. I've debugged the VBA code above: the duration is reset right after you set a direction. In my practice, I changed some property (it was Word); checking the property right after this showed the property value unchanged. "That's Microsoft Office, baby" ©.

briannesbitt writes:
Any idea on how to trigger a preview to occur?


PowerPointApp.CommandBars.ExecuteMso("AnimationPreview")


Andrei Smolin
Add-in Express Team Leader
Posted 25 Nov, 2015 03:18:26 Top
briannesbitt


Guest


Thanks Andrei. It all worked out well.
Posted 30 Nov, 2015 13:40:28 Top
Andrei Smolin


Add-in Express team


Posts: 18817
Joined: 2006-05-11
You are welcome!


Andrei Smolin
Add-in Express Team Leader
Posted 01 Dec, 2015 03:40:18 Top