Search code examples
exportpowerpointmp4duration

Export powerpoint to mp4 by script with dynamic slide duration


I want to export a lot of powerpoint presentations to mpeg4. With the existing functions in Powerpoint I can set a duration per slide or use a schedule. To make this schedule I have to click through the presentation and record my clicks or alternatively set a time for each slide and animation which is a lot of work.

Is there any way I can create a script in which I can define a mouse click duration? I want a slide with no animations to appear for 3 seconds and a slide with, for example, two animations to appear for 9 seconds (slide + animation1 + animation2).

I don't want to specify a display duration, but a kind of click duration ...

Does anyone have any idea whether something like this is even possible?


Solution

  • Here is a VBA script to set the "Advance on Time" setting for each slide based on the number of animations present on the slide.

    For Each sld In ActivePresentation.Slides
        animationCount = sld.TimeLine.MainSequence.Count
        sld.SlideShowTransition.AdvanceOnTime = msoTrue
        sld.SlideShowTransition.AdvanceTime = animationCount * 3 + 3
    Next
    
    ActivePresentation.CreateVideo "C:\SomePath\Filename.mp4", True
    

    In this example, if there are animations on the slide, with this line, we set the time to 3 times the animation count plus 3, as following your example. If we have a slide with 2 animations will have an "Advance on time" duration set to 2*3+3=9 seconds. Change this based on your needs.

            sld.SlideShowTransition.AdvanceTime = animationCount * 3 + 3
    

    The last line allows you to export to video with timings.

    Here is another example where you can specify the no-animation to not have advance on time setting but provide a default duration if you want:

    For Each sld In ActivePresentation.Slides
        animationCount = sld.TimeLine.MainSequence.Count
        If animationCount >= 1 Then
            sld.SlideShowTransition.AdvanceOnTime = msoTrue
            sld.SlideShowTransition.AdvanceTime = animationCount * 3 + 3
        Else
            sld.SlideShowTransition.AdvanceOnTime = msoFalse
        End If
    Next
    
    ActivePresentation.CreateVideo "C:\SomePath\Filename.mp4", True, 3
    

    (if you are unfamiliar with VBA we can possibly find some documentation & tutorials)