-
-
Save pcmoritz/4b0e1be7f2dfcc4e51e2ace50426f67d to your computer and use it in GitHub Desktop.
Option Explicit | |
Sub AddElements() | |
Dim shp As Shape | |
Dim i As Integer, n As Integer | |
n = ActivePresentation.Slides.Count | |
For i = 1 To n | |
Dim s As Slide | |
Set s = ActivePresentation.Slides(i) | |
s.SlideShowTransition.Hidden = msoTrue | |
Dim max As Integer: max = AnimationElements(s) | |
Dim k As Integer, s2 As Slide | |
For k = 1 To max | |
Set s2 = s.Duplicate(1) | |
s2.Name = "AutoGenerated: " & s2.SlideID | |
s2.SlideShowTransition.Hidden = msoFalse | |
Dim oshp As Shape | |
With s2.Shapes | |
Set oshp = .AddTextbox(msoTextOrientationHorizontal, 10, 10, 100, 50) | |
oshp.TextFrame.TextRange.Font.Name = "Arial" | |
oshp.TextFrame.TextRange.Font.Size = 12 | |
oshp.TextFrame.TextRange.InsertAfter "" & i | |
End With | |
s2.MoveTo ActivePresentation.Slides.Count | |
Dim i2 As Integer, h As Shape | |
Dim Del As New Collection | |
For i2 = s2.Shapes.Count To 1 Step -1 | |
Set h = s2.Shapes(i2) | |
If Not IsVisible(s2, h, k) Then Del.Add h | |
Next | |
Dim j As Integer | |
For j = s.TimeLine.MainSequence.Count To 1 Step -1 | |
s2.TimeLine.MainSequence.Item(1).Delete | |
Next | |
For j = Del.Count To 1 Step -1 | |
Del(j).Delete | |
Del.Remove j | |
Next | |
Next | |
Next | |
End Sub | |
'is the shape on this slide visible at point this time step (1..n) | |
Function IsVisible(s As Slide, h As Shape, i As Integer) As Boolean | |
'first search for a start state | |
Dim e As Effect | |
IsVisible = True | |
For Each e In s.TimeLine.MainSequence | |
If e.Shape Is h Then | |
IsVisible = Not (e.Exit = msoFalse) | |
Exit For | |
End If | |
Next | |
'now run forward animating it | |
Dim n As Integer: n = 1 | |
For Each e In s.TimeLine.MainSequence | |
If e.Timing.TriggerType = msoAnimTriggerOnPageClick Then n = n + 1 | |
If n > i Then Exit For | |
If e.Shape Is h Then IsVisible = (e.Exit = msoFalse) | |
Next | |
End Function | |
'How many animation steps are there | |
'1 for a slide with no additional elements | |
Function AnimationElements(s As Slide) As Integer | |
AnimationElements = 1 | |
Dim e As Effect | |
For Each e In s.TimeLine.MainSequence | |
If e.Timing.TriggerType = msoAnimTriggerOnPageClick Then | |
AnimationElements = AnimationElements + 1 | |
End If | |
Next | |
End Function | |
Sub RemElements() | |
Dim i As Integer, n As Integer | |
Dim s As Slide | |
n = ActivePresentation.Slides.Count | |
For i = n To 1 Step -1 | |
Set s = ActivePresentation.Slides(i) | |
If s.SlideShowTransition.Hidden = msoTrue Then | |
s.SlideShowTransition.Hidden = msoFalse | |
ElseIf Left$(s.Name, 13) = "AutoGenerated" Then | |
s.Delete | |
End If | |
Next | |
End Sub |
thank you. however, this only works for animation sequence set on click. It doesn't work on such animation that starts with previous. Is it possible to code that as well?
Thanks!
Thanks!
This is good advice. It seems to me that a professional person should be able to create and customize animations for presentations. I support creative coding, but it seems to me that sometimes ready-made solutions are needed. I ordered https://masterbundles.com/downloads/disney-powerpoint-template-2020-50-unique-slides/ a pc of cool presentation themes with animated elements. It seems to me that this saves time on coding unique elements. The main task is to create a beautiful visualization.
thanks !~
Very useful! thank you very much!
thank you. however, this only works for animation sequence set on click. It doesn't work on such animation that starts with previous. Is it possible to code that as well?
Yes, much desired feature
Thank you!! Very helpful!!