Search code examples
vbapowerpoint

Powerpoint VBA: How to specify the direction of a Float In Entrance Effect


I am trying to add a float in entrance effect to an picture using VBA in Microsoft Office PowerPoint.

I would like the float in animation to go in the downwards direction

Here is my code:

Sub add_pic_float_in()


' Insert the Picture
Set myDocument = ActivePresentation.Slides(1)

myDocument.Shapes.AddPicture FileName:="C:\Users\forson\Pictures\Picture.svg", LinkToFile:=msoTrue, SaveWithDocument:=msoTrue, _
    Left:=a * 10, Top:=-1000, Width:=359.055, Height:=1284.803

' Crop the Image
    With myDocument.Shapes(1)
        .Name = "Picture 1"
        .PictureFormat.CropLeft = 140
        .PictureFormat.CropRight = 130
        .PictureFormat.CropTop = 650
    End With

' Create shape
Dim picture As Shape

Set picture = myDocument.Shapes(1)

' Create Effect
Dim floatin As Effect

' Set Effect to Picture

Set floatin = myDocument.TimeLine.MainSequence.AddEffect(Shape:=picture, effectId:=msoAnimEffectFloat)
        floatin.Timing.Duration = 1
        floatin.EffectParameters.Direction = msoAnimDirectionDown
        floatin.Timing.TriggerType = msoAnimTriggerWithPrevious

End Sub

However, I run into this error:

"Run-time error": '-2147188160 (80048240)': EffectParameters (unknown member): invalid request."

And when I remove the line "floatin.EffectParameters.Direction = msoAnimDirectionDown", it produces an object with an animation, but it is not a "float in" animation.

I have tried looking here and here but I cannot find a solution.


Solution

  • Setting effectId:=msoAnimEffectFloat to effectId:=msoAnimEffectDescend creates a float down animation.

    No need to specify the .EffectParameters.Direction