通过Excel将PPTX文件保存为PDF

5
我可以帮助您翻译以下内容,这是一个关于IT技术的问题:

我想将给定路径下的所有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

错误信息

Presentation.SaveAs :  Invalid enumeration value. 

不知道哪里做错了?

和这个问题相同,但解决方案对我没有用 - Excel宏将pptx另存为pdf;代码出错


哪个版本的Excel? - Edward
1个回答

7

您正在进行晚期绑定PowerPoint.Application,因此其枚举值未在全局VBA命名空间中公开或可用。

由于您未添加option explicit来警告您声明的变量,因此使用未声明的ppSaveAsPDF不会引起错误,但也没有值。

请添加:

const ppSaveAsPDF as long = 32

将期望值提供给模块顶部的 SaveAs


啊,我明白了。非常感谢。这让我很疯狂。 - Boosted_d16

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接