我是VBScript的新手,我有一个小任务:以“后台”模式将ppt / pptx文件导出到视频(WMV)。我通过Internet搜索,现在有了这个脚本:
'''
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
'''
大多数情况下都可以正常工作。输出消息是“转换完成!”。但是会弹出一个“是-否”对话框:“此演示文稿当前正在导出到视频。关闭此演示文稿将中止该演示文稿的导出。您是否仍要关闭?”。现在,我需要避免显示此对话框。我尝试使用“睡眠延迟”,但没有成功。是否可以避免此对话框?最后使用PowerPoint 2016。谢谢。
如果关闭On Error Resume Next
,则会在未声明的PpMediaTaskStatus上看到运行时错误,即,在此处声明或使用其数字值
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