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

我们在Excel中embeddedpptx文件,然后使用Excel VBA代码(如下图)打开,然后将pptx文件另存为用户的驱动器,然后根据Excel计算以编程方式修改pptx内容。
下面的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)对于普通文档(不是embedded在Excel中)工作正常,但是当我在打开的embedded式pptm中运行它时失败。 在2013年和2010年embedded式pptm的工作正常。

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

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

Windows操作系统版本似乎并不重要。 不适用于Mac版Office。

任何方式来解决或解决这个错误? 还是有另外一种方法来做同样的事情(修改embedded式pptx的副本,以便embedded式pptx不被修改)? 或者,这个错误只发生在我们的Office 2016个人电脑上?

对embedded式演示文稿使用SaveAsSaveCopyAs时,PowerPoint 2016似乎失败。

解决方法是打开演示文稿,创build一个新的演示文稿,然后将内容从embedded的演示文稿复制到新的演示文稿。 然后,您可以closuresembedded式演示文稿,然后按需要保存新演示文稿。

我已经演示了复制幻灯片,但是您可能需要以编程方式复制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 

我在另一个论坛上发现了这个可能的答案,它为我保存了一个PPTX文件作为一个PPTX文件

更改

 PPTPres.SaveAs Filename:=sFileName 

 PPTPres.SaveAs sFileName 

我的是:

 PPTPres.SaveCopyAs sFileName 

然后我打开新文件并closuresPPTM文件