Search code examples
vbapowerpoint

How to wait for a "SaveAs" operation to complete?


I'm working on a VBA script that SaveAs all slides of a PPT as MP4 videos. Until now, everything works fine, except that everytime I launch the script, I hit the 10 videos queue cap. To prevent this, I would like to find a way to stop the script until Powerpoint finishes to export the video, then repeats the process as long as there are videos in the Powerpoint.

The code :

Sub export()

    Dim Default, NameValue As Integer
    Dim BoxMessage, BoxTitle As String

    ' InputWindow, to get slide number
    BoxTitle = "Fenetre input valeur minimale"
    BoxMessage = "Rentrer le numero de la premiere slide exportee."

    BoxValue = InputBox(BoxMessage, BoxTitle, "Exemple : 20")

    ' Hide all slides
    For i = 1 To ActivePresentation.Slides.Count
        ActivePresentation.Slides(i).SlideShowTransition.Hidden = True
    Next

    ' For each slide, show the slide, SaveAs a videoMP4, hide the slide
    For i = 1 To ActivePresentation.Slides.Count

        If BoxValue <> 1 Then
            If i = 1 Then
                NameValue = BoxValue
            Else: NameValue = BoxValue + i
            End If
            
        Else: NameValue = i
        End If
        
        ActivePresentation.Slides(i).SlideShowTransition.Hidden = False
        ActivePresentation.SaveAs "s" & NameValue & ".mp4", ppSaveAsMP4
        
        ActivePresentation.Slides(i).SlideShowTransition.Hidden = True
    Next

End Sub

I saw "Application.Wait", but I don't know how much time an export would take (I work with heavy powerpoints, and exports may take between 20s and 90s), and how to get that info. I cannot use DIR, since when you're exporting a video, Powerpoint already creates a file with the appropriate name in the appropriate directory.


Solution

  • I did not find a reliable method to check if the export is done before trying to export other slides. I think it's because VBA does not support this kind of precision. So instead, I'll check around Powershell and such, to see if there are solutions to my problem.