跨软件将ppt用exportasfixedformat转化为pdf的bug的解决办法

如何用vba把ppt文档发布转化为pdf格式文件一文中,介绍了在ppt的vba中用exportasfixedformat方法将ppt转换为pdf的方法。

但是,如果是跨软件调用这个方法转换会报错,比如在excel vba中用如下的代码:

Sub QQ1722187970()
    Const ppFixedFormatTypePDF = 2
    Const ppFixedFormatIntentPrint = 2
    Const ppFixedFormatIntentScreen = 1
    Dim oPPT
    Set oPPT = CreateObject("PowerPoint.Application")
    With oPPT
        .Visible = True
        With .Presentations.Open(Excel.ThisWorkbook.Path & "\" & "test.ppt")
             sName = .Name
             sName = Excel.ThisWorkbook.Path & "\" & Split(sName, ".")(0) & ".pdf"
            .ExportAsFixedFormat sName, ppFixedFormatTypePDF, ppFixedFormatIntentPrint
            .Close
        End With
    End With
End Sub

将弹出“类型不匹配”的错误。pptbug

经查,这个是PPT的BUG,只需要将exportasfixedformat方法中的PrintRange参数的值设置为nothing即可。

如以下代码所示:

Sub QQ1722187970()
    Const ppFixedFormatTypePDF = 2
    Const ppFixedFormatIntentPrint = 2
    Const ppFixedFormatIntentScreen = 1
    Dim oPPT
    Set oPPT = CreateObject("PowerPoint.Application")
    With oPPT
        .Visible = True
        With .Presentations.Open(Excel.ThisWorkbook.Path & "\" & "test.ppt")
             sName = .Name
             sName = Excel.ThisWorkbook.Path & "\" & Split(sName, ".")(0) & ".pdf"
            .ExportAsFixedFormat sName, ppFixedFormatTypePDF, ppFixedFormatIntentPrint, PrintRange:=Nothing
            .Close
        End With
    End With
End Sub

 

       

发表评论