0

I've got 300+ PowerPoint files in a folder. I want to open them one by one, export them to video, then close the PowerPoint files once the export is done.

I've seen numerous sample VBA code that open all the files at one go, do the export & don't close the files. I foresee that this method will not work for me as my pc will crash if all 300+ files are opened & exported at the same time.

This is a sample code that I picked up from this site. I need your help to edit it. I've got no experience in VBA so I've no idea how to loop it properly. Thanks.

Sub exportvideo()
    Dim strFileName As String
    Dim strFolderName As String
    Dim PP As Presentation

    'set default directory
    strFolderName = Environ("USERPROFILE") & "\Desktop\New folder\"
    strFileName = Dir(strFolderName & "\*.pptx")
    Do While Len(strFileName) > 0
       Set PP = Presentations.Open(strFolderName & "\" & strFileName)
        'code to export to video

PP.CreateVideo FileName:=strFolderName & strFileName & ".mp4", _
                                          UseTimingsAndNarrations:=True, _
                                          VertResolution:=1024, _
                                          FramesPerSecond:=30, _
                                          DefaultSlideDuration:=5, _
                                          Quality:=100

    strFileName = Dir

    Loop

'PP.Close
End Sub

I'm running PowerPoint 2016 on Windows 10.

braX
  • 11,506
  • 5
  • 20
  • 33
webportal
  • 53
  • 5
  • If I "uncomment" the PP.Close & place it anywhere (inside or outside the loop), the files will be closed before the export process can start. Anyway, the PP.Close is only part of the problem. The other part is how not to open all 300+ files at one go but instead open them one by one, complete the export & close them. – webportal Jun 01 '20 at 16:40
  • 2
    I/O operations (copy, paste, save, open, export, import, etc.) normally require delay loops to prevent your code out-running the I/O process. This thread has a couple of solutions: https://stackoverflow.com/questions/57268161/sleep-wait-timer-in-powerpoint-vba-thats-not-cpu-intensive You can also search on "doevents loop" for another potential solution. – John Korchok Jun 01 '20 at 16:48

0 Answers0