通过excel将pptx保存为pdf

Boo*_*d16 5 pdf powerpoint vba save-as

我试图将给定路径中的所有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\1_ 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
Run Code Online (Sandbox Code Playgroud)

错误消息

Presentation.SaveAs :  Invalid enumeration value. 
Run Code Online (Sandbox Code Playgroud)

看不出我做错了什么?

同样的问题,但解决方案对我没有用 - Excel宏将pptx保存为pdf; 代码错误

Ale*_* K. 7

您是后期绑定,PowerPoint.Application因此其枚举值不会在全局VBA名称空间中公开或可用.

由于您没有添加option explicit警告您未声明的变量,因此您对未声明的变量的使用ppSaveAsPDF不会导致错误,但没有任何价值.

加:

const ppSaveAsPDF as long = 32
Run Code Online (Sandbox Code Playgroud)

在模块的顶部提供预期值SaveAs.