VBScript将ppt/pptx导出到WMV
我是VBScript新手,我有一个小任务:以“后台”模式将ppt/pptx文件导出到视频(WMV)。我在互联网上搜索,现在我有了以下脚本:VBScript将ppt/pptx导出到WMV,vbscript,powerpoint,Vbscript,Powerpoint,我是VBScript新手,我有一个小任务:以“后台”模式将ppt/pptx文件导出到视频(WMV)。我在互联网上搜索,现在我有了以下脚本: ''' On Error Resume Next Dim oPowerPointApp Set oPowerPointApp = CreateObject("PowerPoint.Application") If Err.Number = 0 Then oPowerPointApp.DisplayAlerts = ppAlertsNone Dim
'''
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在我这边使用。谢谢。如果您关闭“错误恢复下一步”上的
,您将在“未声明”上看到运行时错误,即声明它或使用其数值,如下所示
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
那么,oPowerPointApp.DisplayAlerts=ppAlertsNone
也会有问题吗?我不知道上面是否声明了这一点,如果没有-声明有意义,或者设置为真/假,因为默认情况下vbs会将未知值转换为假。是的,ppAlertsNone
对应于1
。使用数值代替PpMediaTaskStatus对我有效。谢谢。但是,删除“出错后继续下一步”行会导致脚本非常快地退出,PowerPoint进程从未停止执行某些操作(它会永远以10-15%的速度加载CPU)。@АаааСааааСааааааааааа。