Search code examples
vbaanimationpowerpointshapestimeline

Copying animation and sequence information between powerpoint shapes


I'm trying to replace all shape objects on the slide (pictures) with shape objects of another type (rectangular shape). I can delete old object and create new, but i will loose all animation information and sequence order. Is it possible to store animation information and order in timeline, and copy it to the new shape object?


Solution

  • Well, i have found a solution myself, hope someone could find it useful. So, it is not necessary to copy animation information from old shape to a new one, just cycle through sequence's items and replace the shape object refrence to the new shape. Like this:

    On Error Resume Next
    Dim shp1 As Shape 'old shape
    Set shp1 = ActivePresentation.Slides(1).Shapes(3)
    
    Dim shp2 As Shape 'new shape
    Set shp2 = ActivePresentation.Slides(1).Shapes.AddPicture("c:\imgres2.jpg", msoFalse, msoTrue, 0, 0) 'it is important to create new shape before cycling through existing ones.
    For i = ActivePresentation.Slides(1).TimeLine.MainSequence.count To 1 Step -1
        'using "is" opeartor to compare refrences
        If shp1 Is ActivePresentation.Slides(1).TimeLine.MainSequence.Item(i).Shape Then
            ActivePresentation.Slides(1).TimeLine.MainSequence.Item(i).Shape = shp2
        End If
    Next i
    shp1.Delete 'delete the old shape