【问题标题】:save pptx as pdf through excel通过excel将pptx保存为pdf
【发布时间】:2015-07-11 04:50:08
【问题描述】:

我正在尝试将给定路径中的所有 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 macro to save pptx as pdf; error with code

【问题讨论】:

  • 哪个版本的 Excel?

标签: vba pdf powerpoint save-as


【解决方案1】:

您正在后期绑定 PowerPoint.Application,因此它的枚举值不会在全局 VBA 命名空间中公开或可用。

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

添加:

const ppSaveAsPDF as long = 32

向模块顶部提供期望值给SaveAs

【讨论】:

  • 啊啊啊我明白了。非常感谢。快把我逼疯了。
猜你喜欢
  • 1970-01-01
  • 2020-01-30
  • 2021-05-30
  • 2018-08-22
  • 1970-01-01
  • 2021-05-31
  • 1970-01-01
  • 1970-01-01
  • 2021-11-21
相关资源
最近更新 更多