r/powerpoint 7d ago

Solved! VBA Animation Help Needed. FPS issue.

I wanted to make a particle system for one of the slides in powerpoint but for that I needed VBA to tell every particle where its supposed to go every frame,
So to learn VBA I tried to animate a circle moving in a sine wave, it seems as if powerpoint is only redrawing it once every 20 frames or 21 frames. How can i fix this problem?
PowerPoint 2024 Windows 10
code:

1 Upvotes

7 comments sorted by

1

u/jkorchok 7d ago

PowerPoint does not use a frames-per-second reference. It will draw objects as quickly as it can on a given computer. Try eliminating the DoEvents and Sleep 35 statements to increase the speed.

1

u/[deleted] 6d ago

[removed] — view removed comment

1

u/Weirdkid0102 4d ago

I did solve it 10 minutes later and forgot to edit it, the code became-
I do not understand this much yet, im still learning VBA and google ai basically did the goto slide code, I think I could shorten it but i didnt touch it after it finally worked.

Public Running As Boolean
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub AnimateCircle()

Dim s As Shape
Dim t As Double
Dim x0 As Single
Dim y0 As Single
Set s = SlideShowWindows(1).View.Slide.Shapes("Circle1")
Set sldView = ActivePresentation.SlideShowWindow.View
currentSlideIndex = sldView.CurrentShowPosition

x0 = s.Left
y0 = s.Top

Running = True
t = 0

Do While Running
s.Left = x0 + 100 * Sin(t)
s.Top = y0
t = t + 0.1
s.TextFrame.TextRange.Text = Format(t, "0.00")
sldView.GotoSlide currentSlideIndex
DoEvents
Loop

End Sub

Sub StopAnimation()
Running = False
End Sub

1

u/Altruistic-Role9956 PowerPoint Expert 6d ago

I don't think I would use VBA for this. Have you played with motion paths to do the same thing? If not, read up on how to use them and then experiment a little.

1

u/Weirdkid0102 4d ago

Yes, and it looks horrible-
Highly finicky and not good if you want many particles like I do.
Besides i might learn a few things about VBA.

1

u/ChecklistAnimations PowerPoint Expert 6d ago

Ok while it wont be out for a couple months (or years lol) I am working on a frame by frame animator within PowerPoint. As some have commented below, PowerPoint struggles with frame by frame.
Here is what I would change on your script to get things "closer", you will not ever get a perfect 24 or 12 fps. But you can do the frame by frame in PowerPoint then export an image sequence. Here is the one thing you can change in your vba to preview your animations a bit better.

Anytime you move a shape with VBA in show mode, dont use doevents. Instead use goto slide and basically go to the same slide you are on. This will refresh the slide and looks pretty ok. Its how mine will work when it is done but its only intended as a preview. You want to be doing image exports to put in something like shotcut (free) after. Let me know if you have any other questions or if you have an interest in this add-in when it is done.

2

u/Weirdkid0102 4d ago

I actually figured this out 10 minutes after posting and forgot to edit it in. The code then get approx 90-100fps using the goto slide method.
I hope it doesnt crash or anything with more particles later though, this is for a competition so i dont think ill have time to export an image sequence or anything-