VBA Macro for PowerPoint to format videos

Guille01 0 Reputation points
2024-03-06T23:09:04.3633333+00:00

I 'm trying to format automatically  all the videos in a PowerPoint presentation doing the following:

  1. Maximize the size of the video in the slide. 
  2. Center the video in the slide.
  3. Playing the video in a continuous loop.
  4. Playing the video automatically when the slide starts.

The first 3 work fine, but the fourth does not. 

Any idea what could be the problem?

Here is the code I'm using:

Sub formatVideos()

Dim miDiapositiva As Slide

Dim miForma As Shape

'ancho diapositiva

anchoDiapositiva = ActivePresentation.PageSetup.SlideWidth

altoDiapositiva = ActivePresentation.PageSetup.SlideHeight

' Itera a través de todas las diapositivas

For Each miDiapositiva In ActivePresentation.Slides

        ' Itera a través de todas las formas en la diapositiva actual

        For Each miForma In miDiapositiva.Shapes

               ' Verifica si la forma es un objeto de video

                    If miForma.Type = msoMedia Then

                    miForma.AnimationSettings.Animate = msoTrue

                    ' Cambia el tamaño del video (por ejemplo, 640x480 píxeles)

                    miForma.Width = anchoDiapositiva

                    miForma.Height = altoDiapositiva

                    ' Centra

                    anchoVideo = miForma.Width

                    miForma.Left = 0

                    ' Centra el video verticalmente

                    altoVideo = miForma.Height

                    miForma.Top = 0

                    'Playing continuously

                    miForma.AnimationSettings.PlaySettings.LoopUntilStopped = msoTrue

                    'starts automatically

                    miForma.AnimationSettings.PlaySettings.PlayOnEntry = msoTrue

                End If

           Next miForma

    Next miDiapositiva

End Sub

Microsoft 365 and Office | Development | Other
Microsoft 365 and Office | Install, redeem, activate | For business | Windows
Microsoft 365 and Office | PowerPoint | For business | Windows
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. John Korchok 6,416 Reputation points Volunteer Moderator
    2024-03-07T17:06:59.07+00:00

    AnimationSettings won't do it. Here's how to set a video to autoplay:

    Sub PlayVideoAutomatically()
         Dim oShp As Shape
         Set oShp = ActivePresentation.Slides(2).Shapes(1)     
         ActivePresentation.Slides(2).TimeLine.MainSequence.AddEffect Shape:=oShp, effectId:=msoAnimEffectMediaPlay, trigger:=msoAnimTriggerAfterPrevious 
    End Sub
    
    

  2. Felipe Alcantara 0 Reputation points
    2024-07-11T15:24:57.3233333+00:00

    To autoplay all videos, the following script worked for me:

    Sub AutoPlayAllVideos()
        Dim sld As Slide
        Dim sh As Shape
        Dim AnimationEffect As Effect
        Dim Behaviour As AnimationBehavior
        
        For Each sld In ActivePresentation.Slides
            For Each sh In sld.Shapes
                If sh.Type = msoMedia Then
                    If sh.MediaType = ppMediaTypeMovie Then
                        With sh.AnimationSettings
                            .AdvanceMode = ppAdvanceOnTime
                            .AdvanceTime = 0
                            With .PlaySettings
                                .PlayOnEntry = msoTrue
                                .PauseAnimation = msoFalse
                                .LoopUntilStopped = msoFalse
                            End With
                        End With
                    End If
                End If
            Next sh
        Next sld
    End Sub
    

    I tried only setting .PlayOnEntry = msoTrue , but it wasn't enough. It seems that you have to add the .AdvanceMode = ppAdvanceOnTime, so the animation starts automatically after some time, and then set .AdvanceTime = 0, so the "some time" becomes imediatelly at start.

    I hope it helps!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.