通过 excel 将 pptx 保存为 pdf
save pptx as pdf through excel
我正在尝试将给定路径中的所有 pptx 文件转换为 pdf 文件。
我的代码:
Sub pptxtopdf()
Dim ppt As Object
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer
On Error Resume Next
Set ppt = GetObject(, "PowerPoint.Application")
If ppt Is Nothing Then
Set ppt = CreateObject("PowerPoint.Application")
End If
On Error GoTo 0
'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object
Set objFolder = objFSO.GetFolder("P:\Operations\Data & Deliverables\Projects\Amica\presentation_workspace_ spring 2015\Presentations\Volvo")
i = 1
'loops through each file in the directory
For Each objFile In objFolder.Files
Set WDReport = ppt.Presentations.Open(objFile.Path)
Dim FileName2 As String
FileName2 = Replace(objFile.Path, "pptx", "pdf")
'WDReport.ExportAsFixedFormat FileName2, ppFixedFormatTypePDF
WDReport.SaveAs FileName2, ppSaveAsPDF
WDReport.Close
ppt.Quit
Set ppt = Nothing
Set WDReport = Nothing
i = i + 1
Next objFile
End Sub
错误消息
Presentation.SaveAs : Invalid enumeration value.
看不出我做错了什么?
与此处相同的问题,但解决方案对我不起作用 -
您是后期绑定 PowerPoint.Application
,因此它的枚举值不会在全局 VBA 命名空间中公开或可用。
由于您没有添加 option explicit
来警告您未声明的变量,因此您使用未声明的 ppSaveAsPDF
不会导致错误,但没有任何价值。
添加:
const ppSaveAsPDF as long = 32
到模块顶部提供期望值SaveAs
。
我正在尝试将给定路径中的所有 pptx 文件转换为 pdf 文件。
我的代码:
Sub pptxtopdf()
Dim ppt As Object
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer
On Error Resume Next
Set ppt = GetObject(, "PowerPoint.Application")
If ppt Is Nothing Then
Set ppt = CreateObject("PowerPoint.Application")
End If
On Error GoTo 0
'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object
Set objFolder = objFSO.GetFolder("P:\Operations\Data & Deliverables\Projects\Amica\presentation_workspace_ spring 2015\Presentations\Volvo")
i = 1
'loops through each file in the directory
For Each objFile In objFolder.Files
Set WDReport = ppt.Presentations.Open(objFile.Path)
Dim FileName2 As String
FileName2 = Replace(objFile.Path, "pptx", "pdf")
'WDReport.ExportAsFixedFormat FileName2, ppFixedFormatTypePDF
WDReport.SaveAs FileName2, ppSaveAsPDF
WDReport.Close
ppt.Quit
Set ppt = Nothing
Set WDReport = Nothing
i = i + 1
Next objFile
End Sub
错误消息
Presentation.SaveAs : Invalid enumeration value.
看不出我做错了什么?
与此处相同的问题,但解决方案对我不起作用 -
您是后期绑定 PowerPoint.Application
,因此它的枚举值不会在全局 VBA 命名空间中公开或可用。
由于您没有添加 option explicit
来警告您未声明的变量,因此您使用未声明的 ppSaveAsPDF
不会导致错误,但没有任何价值。
添加:
const ppSaveAsPDF as long = 32
到模块顶部提供期望值SaveAs
。