Excel VBA 无法在 Office 2016 中另存为嵌入式 PowerPoint 演示文稿

Excel VBA Can't SaveAs Embedded PowerPoint Presentation in Office 2016

我们在Excel中嵌入pptx文件,然后使用ExcelVBA代码(如下)打开,然后将pptx文件另存为用户的驱动器,然后通过编程修改pptx 内容基于 Excel 计算。
下面的 Excel VBA 代码可以很好地控制 PowerPoint 2010 和 2013,但不再适用于 PowerPoint 2016。
注意:我有类似的 Word 代码,它适用于 Word 2016(和之前的版本)。

Sub OpenCopyOfEmbeddedPPTFile() 'works with Office 2010 and 2013, but not on Office 2016
    Dim oOleObj As OLEObject
    Dim PPTApp As Object
    Dim PPTPres As Object
    Dim sFileName As String
    Set oOleObj = ActiveSheet.Shapes("PPTObj").OLEFormat.Object 'name of the embedded pptx object
    Set PPTApp = CreateObject("Powerpoint.Application")
    PPTApp.Visible = True
    sFileName = "C:\Users\Me\Documents\testPPT.pptx"
    OleObj.Verb Verb:=xlVerbOpen 'it opens successfully
    Set PPTPres = oOleObj.Object
    PPTPres.SaveAs Filename:=sFileName 'fails here (in Office 2016)
    PPTPres.Close
    GetObject(, "PowerPoint.Application").Presentations.Open sFileName
    'code to modify the Presentation (copy of the embedded pptx) based on Excel calculations
End Sub

错误:
运行-时间错误'-2147467259 (80004005)': Presentation.SaveAs: PowerPoint 保存文件时出错。

此外,以下 PowerPoint VBA(不是 Excel VBA)对于普通文档(未嵌入 Excel)工作正常,但当我 运行 它在打开的嵌入式 pptm 中。在 2013 年和 2010 年的嵌入式 pptm 中运行良好。

ActivePresentation.SaveAs FileName:="C:\Users\Me\Documents\testPPT.pptm"

错误: 运行-时间错误“-2147467259 (80004005)”:演示文稿(未知成员):PowerPoint 保存文件时出错。

Windows OS 版本好像无所谓。不适用于 Mac.

的 Office

有什么方法可以解决或解决此错误?还是有另一种方法可以做同样的事情(修改嵌入式 pptx 的副本,这样嵌入式 pptx 就不会被修改)?还是这个错误只发生在我们的 Office 2016 电脑上?

PowerPoint 2016 在对嵌入式演示文稿使用 SaveAsSaveCopyAs 时似乎失败。

解决方法是打开演示文稿,创建一个新的演示文稿,然后将内容从嵌入的演示文稿复制到新的演示文稿中。然后您可以关闭嵌入的演示文稿,并根据需要保存新的演示文稿。

我已经演示了如何复制幻灯片,但您可能需要以编程方式复制 BuiltInDocumentProperties 和其他非幻灯片内容。

Option Explicit

Sub OpenCopyOfEmbeddedPPTFile() 'works with Office 2010 and 2013, but not on Office 2016
    Dim oOleObj As OLEObject
    Dim PPTApp As Object
    Dim PPTPres As Object
    Dim PPTNewPres As Object
    Dim sFileName As String
    Set oOleObj = ActiveSheet.Shapes("PPTObj").OLEFormat.Object 'name of the embedded pptx object

    oOleObj.Verb 3
    Set PPTPres = oOleObj.Object

    Set PPTApp = PPTPres.Application
    PPTApp.Visible = True

    'We can't save the embedded presentation in 2016, so let's copy the clides to a new presentation
    Set PPTNewPres = PPTApp.Presentations.Add
    PPTPres.Slides.Range.Copy
    PPTNewPres.Slides.Paste

    'We may need to copy other things, like BuiltInDocumentProperties
    'TODO

    'Close the original
    PPTPres.Close

    sFileName = "C:\Users\Me\Documents\testPPT121.pptx"
    sFileName = "C:\users\andrew\desktop\testPPT12111-FOOJANE.pptx"
    PPTNewPres.SaveAs sFileName

    'code to modify the Presentation (copy of the embedded pptx) based on Excel calculations

    'Quit PPT
    'PPTNewPres.Close
    'PPTApp.Quit

End Sub

我在另一个论坛找到了这个可能的答案,它对我有用,将 PPTM 文件另存为 PPTX 文件作为副本

改变

PPTPres.SaveAs Filename:=sFileName 

PPTPres.SaveAs sFileName

我的是:

PPTPres.SaveCopyAs sFileName

然后我打开新文件并关闭PPTM文件