簡體   English   中英

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

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

我們在Excel中嵌入pptx文件,然后使用Excel VBA代碼(如下所示)打開,然后將ptx文件另存為用戶的驅動器,然后以編程方式修改基於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)適用於普通文檔(未嵌入Excel),但在打開的嵌入式pptm中運行時失敗。 在2013年和2010年嵌入式pptm工作正常。

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

錯誤:運行時錯誤'-2147467259(80004005)':演示文稿(未知成員):PowerPoint保存文件時出錯。

Windows操作系統版本似乎並不重要。 在Office for Mac上不起作用。

有任何方法可以解決或解決此錯誤嗎? 或者是否有另一種方法來做同樣的事情(修改嵌入式pptx的副本,以便嵌入式pptx不被修改)? 或者此錯誤僅發生在我們的Office 2016 PC上?

對嵌入式演示文稿使用SaveAsSaveCopyAs時,PowerPoint 2016似乎失敗。

解決方法是打開演示文稿,創建新演示文稿,然后將內容從嵌入演示文稿復制到新演示文稿。 然后,您可以關閉嵌入的演示文稿,並根據需要保存新演示文稿。

我已經演示了復制幻燈片,但您可能需要以編程方式復制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文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM