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

Office
Office
A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.
1,345 questions
PowerPoint
PowerPoint
A family of Microsoft presentation graphics products that offer tools for creating presentations and adding graphic effects like multimedia objects and special effects with text.
227 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,565 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. John Korchok 5,101 Reputation points
    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