2
votes

I'm new to VBScript and I have a small task: export ppt/pptx file to a video(WMV) in a "background" mode. I searched over the Internet and now I have this script:

'''
On Error Resume Next
Dim oPowerPointApp
Set oPowerPointApp = CreateObject("PowerPoint.Application")
If Err.Number = 0 Then
   oPowerPointApp.DisplayAlerts = ppAlertsNone
   Dim oPresentation
   Set oPresentation = oPowerPointApp.Presentations.Open("D:\TestPresentation.pptx", msoTrue, , msoFalse)
   If Err.Number = 0 Then
      ' True - use the existing transitions, 5 sec per slide by default, 720 - height of the video, 30 - fps, 85 - quality[1;100]
      oPresentation.CreateVideo "D:\TestPresentation.wmv", True, 5, 720, 30, 85
      ' Now wait for the conversion to be complete:
      Do
         ' Don't tie up the user interface; add DoEvents to give the mouse and keyboard time to keep up.
         DoEvents
         Select Case oPresentation.CreateVideoStatus
            Case PpMediaTaskStatus.ppMediaTaskStatusDone
               WScript.Echo "Conversion complete!"
               Err.Number = 0
               Exit Do
            Case PpMediaTaskStatus.ppMediaTaskStatusFailed
               WScript.Echo "Conversion failed!"
               Err.Number = 1
               Exit Do
            Case PpMediaTaskStatus.ppMediaTaskStatusInProgress
               WScript.Echo "Conversion in progress" ' For Debug only
            Case PpMediaTaskStatus.ppMediaTaskStatusNone
               ' You'll get this value when you ask for the status and no conversion is happening or has completed.
            Case PpMediaTaskStatus.ppMediaTaskStatusQueued
               WScript.Echo "Conversion queued" ' For Debug only
         End Select
         'WScript.Sleep 200
      Loop
      'WScript.Sleep 5000
      oPresentation.Close
   End If
   oPowerPointApp.Quit
End If
WScript.Echo Err.Number
'''

Mostly it works fine. The output message is "Conversion complete!". But there is a popup Yes-No dialog: "This presentation is currently being exported to video. Closing this presentation will abort pending exports of this presentation. Do you want to close anyway?". And now I need to avoid showing this dialog. I tried to use Sleep delay, but it didn't worked. Is this possible to avoid this dialog ? PowerPoint 2016 is used at my end. Thanks.

1

1 Answers

1
votes

If you switch off On Error Resume Next you will see runtime errors on undeclared PpMediaTaskStatus, i.e. declare it or use its numeric values as here

Do
  Select Case oPresentation.CreateVideoStatus
  Case 3 'PpMediaTaskStatus.ppMediaTaskStatusDone
    WScript.Echo "Conversion complete!"
    Err.Number = 0
    Exit Do
  Case 4 'PpMediaTaskStatus.ppMediaTaskStatusFailed
    WScript.Echo "Conversion failed!"
    Err.Number = 1
    Exit Do
  End Select
  WScript.Sleep 200 'it's in ms, so makes sense to set 1000 (1 sec)
Loop