0% found this document useful (0 votes)
11 views4 pages

Fixed Ambulance Animation

The document contains a VBA macro for PowerPoint that sets up an ambulance animation across multiple slides, with configurable slide durations and a progress tracker. It creates a visual representation of an ambulance moving along a track on each slide, with customizable timings for each slide. Additionally, there is a function to set custom slide times for specific slides, ensuring the total presentation time remains consistent.

Uploaded by

Mo Hamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Fixed Ambulance Animation

The document contains a VBA macro for PowerPoint that sets up an ambulance animation across multiple slides, with configurable slide durations and a progress tracker. It creates a visual representation of an ambulance moving along a track on each slide, with customizable timings for each slide. Additionally, there is a function to set custom slide times for specific slides, ensuring the total presentation time remains consistent.

Uploaded by

Mo Hamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Sub SetupAmbulanceAnimation()

Dim sld As Slide


Dim shpAmbulance As Shape
Dim shpTrack As Shape
Dim eff As Effect
Dim totalSlides As Long
Dim i As Long

' --- CONFIGURATION ---


Dim totalTime As Single: totalTime = 600 ' 10 minutes = 600 seconds
totalSlides = ActivePresentation.Slides.Count ' Get total slide count

' Adjust if you have different slide durations


Dim slideTimePercent() As Single
ReDim slideTimePercent(1 To totalSlides)

' Default: equal time for all slides


Dim j As Long
For j = 1 To totalSlides
slideTimePercent(j) = 1 / totalSlides
Next j

' Progress Track Settings


Dim trackLeft As Single: trackLeft = 50 ' Starting X position
Dim trackTop As Single: trackTop = 500 ' Vertical position of the track
Dim trackHeight As Single: trackHeight = 10 ' Height of the track
Dim trackWidth As Single
trackWidth = ActivePresentation.PageSetup.SlideWidth - (2 * trackLeft) ' Total
track width

' Ambulance Settings


Dim ambulanceWidth As Single: ambulanceWidth = 40
Dim ambulanceHeight As Single: ambulanceHeight = 25

' Create road and ambulance on each slide


Dim cumulativePercent As Single: cumulativePercent = 0

For i = 1 To totalSlides
Set sld = ActivePresentation.Slides(i)

' Remove previous instances if they exist


On Error Resume Next
sld.Shapes("Track").Delete
sld.Shapes("Ambulance").Delete
sld.Shapes("Cross").Delete
On Error GoTo 0

' Create the track/road


Set shpTrack = sld.Shapes.AddShape(msoShapeRectangle, trackLeft, trackTop,
trackWidth, trackHeight)
shpTrack.Name = "Track"
shpTrack.Fill.ForeColor.RGB = RGB(200, 200, 200) ' Gray road
shpTrack.Line.Visible = msoFalse

' Calculate ambulance start position for this slide


Dim startPosX As Single
startPosX = trackLeft + (cumulativePercent * trackWidth)

' Calculate end position for this slide


Dim endPosX As Single
endPosX = startPosX + (slideTimePercent(i) * trackWidth)

' Ensure ambulance stays within slide bounds


If startPosX > (trackLeft + trackWidth - ambulanceWidth) Then
startPosX = trackLeft + trackWidth - ambulanceWidth
End If

' Create ambulance


Set shpAmbulance = sld.Shapes.AddShape(msoShapeRoundedRectangle, startPosX,
trackTop - 15, ambulanceWidth, ambulanceHeight)
shpAmbulance.Name = "Ambulance"
shpAmbulance.Fill.ForeColor.RGB = RGB(255, 0, 0) ' Red ambulance
shpAmbulance.Line.ForeColor.RGB = RGB(0, 0, 0)
shpAmbulance.Line.Weight = 1

' Add cross to make it look like an ambulance


Dim shpCross As Shape
Set shpCross = sld.Shapes.AddShape(msoShapeRectangle, startPosX + 15,
trackTop - 10, 10, 10)
shpCross.Name = "Cross"
shpCross.Fill.ForeColor.RGB = RGB(255, 255, 255) ' White cross
shpCross.Line.Visible = msoFalse

' Group ambulance and cross


Dim groupShapes As ShapeRange
Set groupShapes = sld.Shapes.Range(Array("Ambulance", "Cross"))
Dim grpAmbulance As Shape
Set grpAmbulance = groupShapes.Group
grpAmbulance.Name = "Ambulance"

' Add animation only if there's room to move


If startPosX < endPosX And i < totalSlides Then
' Add motion effect
Set eff = sld.TimeLine.MainSequence.AddEffect(grpAmbulance,
msoAnimEffectCustom, , msoAnimTriggerWithPrevious)

' Calculate distance to move


Dim moveDistance As Single
moveDistance = endPosX - startPosX

' Set up motion path (needs to be a string with relative coordinates)


Dim pathStr As String
pathStr = "M 0 0 L " & moveDistance & " 0 E"

' Apply the path


eff.Behaviors(1).MotionEffect.Path = pathStr

' Set timing - ties to slide duration


eff.Timing.Duration = slideTimePercent(i) * totalTime
eff.Timing.TriggerType = msoAnimTriggerWithPrevious
eff.Timing.TriggerDelayTime = 0

' Start effect immediately when slide appears


eff.Timing.StartTime = 0
End If

' Add percentage text


Dim shpPercent As Shape
Set shpPercent = sld.Shapes.AddTextbox(msoTextOrientationHorizontal,
startPosX, trackTop + trackHeight + 5, 50, 20)
shpPercent.TextFrame.TextRange.Text = Format(cumulativePercent * 100, "0")
& "%"
shpPercent.TextFrame.TextRange.Font.Size = 10

' Update for next slide


cumulativePercent = cumulativePercent + slideTimePercent(i)
Next i

MsgBox "Ambulance progress tracker added to " & totalSlides & " slides,
representing a " & totalTime / 60 & " minute presentation."
End Sub

' Optional: Use this function to set custom times for specific slides
Sub SetCustomSlideTimes()
Dim totalSlides As Long
Dim i As Long
Dim totalTime As Single: totalTime = 600 ' 10 minutes

totalSlides = ActivePresentation.Slides.Count

' Create a collection to store slide durations


Dim slideDurations As New Collection

' Example: Set different durations for slides (in seconds)


' First slide (introduction) takes 45 seconds
slideDurations.Add 45, "1"

' Second slide takes 30 seconds


slideDurations.Add 30, "2"

' Third slide takes 25 seconds


slideDurations.Add 25, "3"

' For slides not explicitly set, calculate evenly


Dim remainingTime As Single
Dim assignedTime As Single
Dim remainingSlides As Long

' Calculate total assigned time


assignedTime = 0
For i = 1 To slideDurations.Count
assignedTime = assignedTime + slideDurations(i)
Next i

' Calculate remaining time and slides


remainingTime = totalTime - assignedTime
remainingSlides = totalSlides - slideDurations.Count

' If not all slides have been assigned times, distribute the remaining time
If remainingSlides > 0 Then
Dim defaultTime As Single
defaultTime = remainingTime / remainingSlides

' Assign default time to remaining slides


For i = slideDurations.Count + 1 To totalSlides
slideDurations.Add defaultTime, CStr(i)
Next i
End If

' At this point, slideDurations contains times for all slides


' You can pass this collection to a modified SetupAmbulanceAnimation
' function that accepts slide durations as a parameter
End Sub

You might also like