View Full Version : [SOLVED:] Swap animation with vba
Jhon90
06-11-2021, 07:11 AM
Sir Paul_Hossler
Need a little help.
I want to swap my entrance animation with the help of vba. I have a group(rectangle & textbox) & want to swap its entrance FloatIn animation to Spinner animation. I run the following code but not working.
For better understand please see the example presentation.
Sub animationswap()
Dim osld As Slide
Dim i As Integer
Dim oeff As Effect
Dim gshp As Shape
Set osld = ActivePresentation.Slides(1)
For j = 1 To 4
Set gshp = osld.Shapes("Group" & j)
For i = 1 To osld.TimeLine.MainSequence.Count
If osld.TimeLine.MainSequence(i).Shape.Id = gshp.Id Then
If osld.TimeLine.MainSequence(i).EffectType = msoAnimEffectFloat Then
Set oeff = osld.TimeLine.MainSequence(i)
oeff.EffectType = msoAnimEffectSpin
End If
End If
Next i
Next j
End Sub
John Wilson
06-11-2021, 08:41 AM
Sir Paul_Hossler
Need a little help.
I want to swap my entrance animation with the help of vba. I have a group(rectangle & textbox) & want to swap its entrance FloatIn animation to Spinner animation. I run the following code but not working.
For better understand please see the example presentation.
Sub animationswap()
Dim osld As Slide
Dim i As Integer
Dim oeff As Effect
Dim gshp As Shape
Set osld = ActivePresentation.Slides(1)
For j = 1 To 4
Set gshp = osld.Shapes("Group" & j)
For i = 1 To osld.TimeLine.MainSequence.Count
If osld.TimeLine.MainSequence(i).Shape.Id = gshp.Id Then
If osld.TimeLine.MainSequence(i).EffectType = msoAnimEffectFloat Then
Set oeff = osld.TimeLine.MainSequence(i)
oeff.EffectType = msoAnimEffectSpin
End If
End If
Next i
Next j
End Sub
John Wilson
06-11-2021, 08:42 AM
If the animation to swap if FloatIn you will probably find it is msoAnimEffectAscend. (I know it makes no sense really but FloatIn is really a slower Ascend) FLOAT is a different animation all together.
Jhon90
06-11-2021, 11:10 PM
Thanks Sir,
First thanks for your suggestion. I change "msoAnimEffectFloat" to "msoAnimEffectAscend" in above code & its working. So FloatIn animation fall under the msoAnimEffectAscend category not under msoAnimEffectFloat thats why its not working.
Now I want to give animation duration so I put
oeff.Timing.Duration = 0.25 & its perfectly working.
But when I put oeff.EffectParameters.Direction = msoAnimDirectionClockwise then its not working & shows error:
EffectParameters(unknown member) : Invalid request.
So how to change the direction(clockwise/anticlockwise)?
John Wilson
06-12-2021, 04:52 AM
Set .EffectParameters.Amount to +number (clockwise) - number (CounterClockwise)
Jhon90
06-12-2021, 08:33 AM
Thanks Sir
Now its working. Sir its little confuse for a newbie to use proper direction property. I want to give clockwise direction & I thought its "msoAnimDirectionClockwise" but I was wrong, its oeff.EffectParameters.Amount = +360;
As its A Spin property that's why I use "Amount" property & give +360 degree rotation for clockwise direction.
So where can I use "msoAnimDirectionClockwise" property? There are limited resource & could not find that answer.
Thanks again for your valuable suggestion.
John Wilson
06-12-2021, 10:35 AM
I have never had cause to use msoAnimDirectionClockwise and don't know where it would be used. Possibly it is from the old animation model that predastes the Timeline but I don't know.
Jhon90
06-16-2021, 04:41 AM
Thanks Sir for valuable information.
Need little help.
Sir now I want to implement this "swap animation" from excel by doing a command button(ActiveX control).
So I create a userform(Userform1) to select "type of animation" & input animation duration value.
For this I insert above vba code in userform & run but animation did not swap.
I am attaching Powerpoint presentation & Excel file for better understanding.
Please 1st open powerpoint & then run the command botton(Swap Animation).
John Wilson
06-16-2021, 05:51 AM
pptx and xlsx files cannot cotain code so there is no code to run + the animations are NOT float in.
Jhon90
06-16-2021, 08:11 AM
Firstly sorry Sir for uploading wrong file.
Sir in this presentation I change "float" to "fly" animation. now I attach the right file.
John Wilson
06-16-2021, 09:14 AM
Your main problem is you are trying to use constants likemsoAnimEffectSpin which ONLY apply to PPT. The EXcel code has no idea what they mean
Either set a reference to the PowerPoint Object model or use the actual values
msoAnimEffectFly=2
msoAnimEffectSpinner=44
msoAnimEffectZoom =23
msoAnimEffectWipe=22
You should declare z as a long not a string. Effect types are NOT strings.
28612
Jhon90
06-16-2021, 12:26 PM
Thanks Sir.
Perfectly working now. Thanks again to guide me & giving valuable information.
Jhon90
06-16-2021, 10:53 PM
Sir,
Now its perfectly working But its takes long time for me 5 min to swap 50(shape) animations. When I run this code in powerpoint directly it takes 05 sec only. So is there any process to reduce time when I run code from excel or run code directly in powerpoint but input takes from userform(I think msgBox can not be configure like userform [drop down menu to select animation]).
Jhon90
06-20-2021, 02:16 AM
Thanks Sir
Now I configured.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.