Consulting

Results 1 to 14 of 14

Thread: Swap animation with vba

  1. #1
    VBAX Regular
    Joined
    Sep 2020
    Location
    https://t.me/pump_upp
    Posts
    40
    Location

    Swap animation with vba

    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
    Attached Files Attached Files
    Last edited by Paul_Hossler; 06-11-2021 at 08:28 AM. Reason: Added CODE tags

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Quote Originally Posted by Jhon90 View Post
    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
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    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.
    Last edited by John Wilson; 06-11-2021 at 08:55 AM.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  4. #4
    VBAX Regular
    Joined
    Sep 2020
    Location
    https://t.me/pump_upp
    Posts
    40
    Location
    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)?

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Set .EffectParameters.Amount to +number (clockwise) - number (CounterClockwise)
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    VBAX Regular
    Joined
    Sep 2020
    Location
    https://t.me/pump_upp
    Posts
    40
    Location
    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.

  7. #7
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    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.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  8. #8
    VBAX Regular
    Joined
    Sep 2020
    Location
    https://t.me/pump_upp
    Posts
    40
    Location
    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).
    Attached Files Attached Files

  9. #9
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    pptx and xlsx files cannot cotain code so there is no code to run + the animations are NOT float in.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  10. #10
    VBAX Regular
    Joined
    Sep 2020
    Location
    https://t.me/pump_upp
    Posts
    40
    Location
    Firstly sorry Sir for uploading wrong file.

    Sir in this presentation I change "float" to "fly" animation. now I attach the right file.
    Attached Files Attached Files

  11. #11
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    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.

    command file.xlsm
    Last edited by John Wilson; 06-16-2021 at 09:24 AM.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  12. #12
    VBAX Regular
    Joined
    Sep 2020
    Location
    https://t.me/pump_upp
    Posts
    40
    Location
    Thanks Sir.
    Perfectly working now. Thanks again to guide me & giving valuable information.

  13. #13
    VBAX Regular
    Joined
    Sep 2020
    Location
    https://t.me/pump_upp
    Posts
    40
    Location
    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]).

  14. #14
    VBAX Regular
    Joined
    Sep 2020
    Location
    https://t.me/pump_upp
    Posts
    40
    Location
    Thanks Sir

    Now I configured.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •