简体   繁体   English

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

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

We embed pptx files in Excel, then use Excel VBA code (like below) to open, then SaveAs the pptx file to the user's drive, then programmatically modify the pptx content based on Excel calculations. 我们在Excel中嵌入pptx文件,然后使用Excel VBA代码(如下所示)打开,然后将ptx文件另存为用户的驱动器,然后以编程方式修改基于Excel计算的pptx内容。
The Excel VBA code below works fine to control PowerPoint 2010 and 2013, but no longer works for PowerPoint 2016. 下面的Excel VBA代码可以很好地控制PowerPoint 2010和2013,但不再适用于PowerPoint 2016。
Note: I have similar code for Word and it works fine for Word 2016 (and prior versions). 注意:我有类似的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

Error: 错误:
Run-time error '-2147467259 (80004005)': Presentation.SaveAs : An error occurred while PowerPoint was saving the file. 运行时错误'-2147467259(80004005)':Presentation.SaveAs:PowerPoint保存文件时发生错误。

Also, the following PowerPoint VBA (not Excel VBA) works fine for normal documents (not embedded in Excel), but fails when I run it in an opened embedded pptm. 此外,以下PowerPoint VBA(不是Excel VBA)适用于普通文档(未嵌入Excel),但在打开的嵌入式pptm中运行时失败。 Works fine in 2013 and 2010 embedded pptm's. 在2013年和2010年嵌入式pptm工作正常。

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

Error: Run-time error '-2147467259 (80004005)': Presentation (unknown member) : An error occurred while PowerPoint was saving the file. 错误:运行时错误'-2147467259(80004005)':演示文稿(未知成员):PowerPoint保存文件时出错。

Windows OS version does not seem to matter. Windows操作系统版本似乎并不重要。 Does not work on Office for Mac. 在Office for Mac上不起作用。

Any way to resolve or workaround this error? 有任何方法可以解决或解决此错误吗? Or is there another way to do the same thing (modify a copy of the embedded pptx so the embedded pptx is not modified)? 或者是否有另一种方法来做同样的事情(修改嵌入式pptx的副本,以便嵌入式pptx不被修改)? Or does this error only occur on our Office 2016 PCs? 或者此错误仅发生在我们的Office 2016 PC上?

PowerPoint 2016 appears to fail when using SaveAs or SaveCopyAs against an embedded presentation. 对嵌入式演示文稿使用SaveAsSaveCopyAs时,PowerPoint 2016似乎失败。

The workaround is to open the presentation, create a new presentation, and then copy the content from the embedded presentation to the new presentation. 解决方法是打开演示文稿,创建新演示文稿,然后将内容从嵌入演示文稿复制到新演示文稿。 You can then close the embedded presentation, and save the new presentation as you wish. 然后,您可以关闭嵌入的演示文稿,并根据需要保存新演示文稿。

I've demonstrated copying the slides, but you may need to programmatically copy BuiltInDocumentProperties and other non-slide content. 我已经演示了复制幻灯片,但您可能需要以编程方式复制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

I found this possible answer in another forum and it worked for me saving a PPTM file as a PPTX file as a copy 我在另一个论坛中找到了这个可能的答案,它可以帮我将PPTM文件保存为PPTX文件作为副本

Change 更改

PPTPres.SaveAs Filename:=sFileName 

to

PPTPres.SaveAs sFileName

Mine was : 我的是:

PPTPres.SaveCopyAs sFileName

I then open the new file and close the PPTM file 然后我打开新文件并关闭PPTM文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用 VBA 从 Excel 打开现有的 PowerPoint 演示文稿 (2016) - Unable to open an existing PowerPoint Presentation (2016) from Excel using VBA 如何使用Excel VBA和userform编辑嵌入在Excel中的PowerPoint演示文稿 - How can I edit a PowerPoint presentation embedded in Excel using Excel VBA and userform 无法从 Excel 打开 Powerpoint 演示文稿 - Can't open Powerpoint presentation from Excel 使用VBA和Excel生成PowerPoint演示文稿 - Generating a powerpoint presentation with VBA and Excel Excel vba将幻灯片复制到现有的PowerPoint演示文稿 - Excel vba to copy slides to an existing powerpoint presentation 打开 Powerpoint 演示文稿并更新 VBA 中的 Excel 链接 - Open a Powerpoint Presentation and update the Excel links in VBA 使用 VBA 从 Excel 中打开 PowerPoint 演示文稿,然后将该演示文稿设置为变量 - Open a PowerPoint presentation from Excel with VBA and then set that presentation to a variable 从 PowerPoint 演示文稿(VBA、powerpoint)打开 Excel 文档 - Open Excel document from a powerpoint presentation (VBA, powerpoint) 在 Excel 中使用 VBA 从 PowerPoint 模板创建新的 PowerPoint 演示文稿 - Create new PowerPoint presentation from PowerPoint template using VBA in Excel Excel 2016 for Mac 中的 VBA 宏:另存为不适用于 CSV 文件格式 - VBA macro in Excel 2016 for Mac: SaveAs will not work with a CSV file format
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM