Link to home
Start Free TrialLog in
Avatar of hindersaliva
hindersalivaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

PowerPoint 2016 - assign OnClick animation to shapes with VBA

I have simplified my problem as follows.

Say, I have 6 shapes on a slide named 'shape1' to 'shape6'.
I want to assign OnClick animations to them in this way with VBA:
Shapes 1 to 3 to turn 'red' on 1st click
Shape 4 to turn 'blue' on next click
Shape 5 and 6 to turn 'green' on next click

Thanks!
SOLUTION
Avatar of John Wilson
John Wilson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hindersaliva

ASKER

JSRW, I only need it to work at design time, so I can live with bugginess to an extent.

I'd like to try it. Can you give me a simple Hello World just to assign the OnClick trigger please?
Thanks.
Found this. Working on it.

Private Sub CommandButton1_Click()

    Dim oshp As Shape
    Dim oslide As Slide

    Set oslide = ActivePresentation.Slides(3)
    
    'Clear all animations
    For i = 1 To oslide.TimeLine.MainSequence.Count
        oslide.TimeLine.MainSequence.Item(1).Delete
    Next
    
    For i = 1 To 6
        Set oshp = oslide.Shapes(i)
        ' Assign an animation to shape
        Set oEffect = oslide.TimeLine.MainSequence.AddEffect(Shape:=oshp, effectId:=msoAnimEffectChangeFillColor, trigger:=msoAnimTriggerAfterPrevious)
        oEffect.EffectParameters.Color2.RGB = RGB(0, 255, 0)
        oEffect.Timing.SmoothEnd = msoTrue
        oEffect.Timing.Duration = 0.2
    Next

End Sub

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yickes!
Yes JRSW, I was testing it and it gave odd results. And then you confirmed it. Oh dear.
Any ideas on how to get round it?
One idea. How about manually creating the 3 shape objects on a spare slide, that already has the animation applied? Than I only need to programmatically create copies of them (re-position, rename) and assign the triggers/trigger-type with VBA. Any reason it would not work? (before I try it out)

Or would that invoke the same bug?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
JRSW, my PowerPoint 2016 can't open it. Says there's a problem with it, even after 'repair'.
Try again pls?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
(Yes, sorry I wasn't familiar with the unblock security feature! Doh!)

Wow! great. That does it perfectly!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial