hindersaliva
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!
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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?
ASKER
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?
Or would that invoke the same bug?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
JRSW, my PowerPoint 2016 can't open it. Says there's a problem with it, even after 'repair'.
Try again pls?
Try again pls?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
(Yes, sorry I wasn't familiar with the unblock security feature! Doh!)
Wow! great. That does it perfectly!
Wow! great. That does it perfectly!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'd like to try it. Can you give me a simple Hello World just to assign the OnClick trigger please?
Thanks.