簡體   English   中英

VBA運行時錯誤438

[英]VBA run time error 438

我試圖寫一個代碼來打開從Excel VBA在PPT更新鏈接PPTX文件。

下面是我得到的代碼,但在代碼試圖更新鏈接我得到的

運行時錯誤438對象不支持此屬性或方法

Sub kunal()

Dim PPObj As Object

Set PPObj = CreateObject("PowerPoint.application")

With PPObj      
    .Presentations.Add

    .Presentations.Open Filename:="Y:\Desktop\Month End\One_Shot\Template AVP Report Package\ABD-OME SDeeson.pptx"

    .Visible = True    
    .UpdateLinks    
    .Presentation.Save

    .Quit    
    Set PPObj = Nothing    
End With

End Sub

438表示您正在嘗試訪問不存在的方法或對象的屬性。 因此,您需要一個表示對象而不是應用程序對象來更新鏈接。

嘗試這樣:

Option Explicit

Sub kunal()

    Dim PPObj As Object
    Dim pptPresentation As Object

    Set PPObj = CreateObject("PowerPoint.application")
    Set pptPresentation = PPObj.presentations.Open("C:\test.pptx")

    With PPObj

        .presentations.Add

        .Visible = True
        pptPresentation.UpdateLinks
        pptPresentation.Save
        pptPresentation.Close

        .Quit
        'Set PPObj = Nothing - No need for this
    End With

End Sub

應用對象MSDN

表示對象MSDN

首先 ,不確定是否需要.Presentations.Add如果在下面的行中要打開現有的Presentation。

其次.UpdateLinks行是Presentation的屬性,而不是PowerPoint.Application的屬性。

Option Explicit

Sub kunal()

Dim ppApp As Object
Dim ppPres As Object

Set ppApp = CreateObject("PowerPoint.application")

With ppApp
    .Visible = True

'    .Presentations.Add ' <-- not sure why you need to open a new Presentation ?
    Set ppPres = .Presentations.Open(Filename:="Y:\Desktop\Month End\One_Shot\Template AVP Report Package\ABD-OME SDeeson.pptx")

    ppPres.UpdateLinks
    ppPres.Save
    ppPres.Close

    .Quit
End With

Set ppPres = Nothing
Set ppApp = Nothing

End Sub

暫無
暫無

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

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