2014-12-13 61 views
0

我想從給定的位置打開一個ppt,並試圖打破ppt中的所有鏈接。一旦打開ppt,我就無法從excel中調用ppt,因此代碼出錯。給我錯誤的代碼行如下 - 「對於ActiveWindow.Slides中的每個Sld」 - 對象不支持此屬性或方法。任何幫助將不勝感激。如何從excel vba調用一個開放的PPT

Sub Breaklinks() 

Dim file As String 
Dim PPT As Object 
Dim Sld As Slide 
Dim Sh As Shape 

file = Cells(4, 2).Value & "\" & Cells(4, 3).Value 

Set PPT = CreateObject("PowerPoint.Application") 
PPT.Visible = True 
PPT.Presentations.Open file 

For Each Sld In ActiveWindow.Slides 
    For Each Sh In Sld.Shapes 
     If Sh.Type = msoLinkedOLEObject Then 
      Sh.LinkFormat.BreakLink 
     End If 
    Next 
Next 

End Sub 

回答

0

你在Excel中,它沒有ActiveWindow.Slides屬性。

試試這樣說:

' At the beginning: 
Dim oPres as Presentation 

' Then instead of this: 
' PPT.Presentations.Open file 
' do this 
Set oPres = PPT.Presentations.Open file 

' then ... 
For Each Sld In oPres.Slides 
    For Each Sh In Sld.Shapes 
     If Sh.Type = msoLinkedOLEObject Then 
      Sh.LinkFormat.BreakLink 
     End If 
    Next 
Next 
+0

喜史蒂夫,感謝您的答覆。當我寫你提到的聲明「設置Pres = PPT.Presentations.Open文件」。我收到錯誤:「預期:聲明結束」。對不起,如果我誤解你的解釋。 – 2014-12-16 09:55:03

+0

啊,對不起。應該設置oPres = PPT.Presentations.Open(文件) – 2014-12-16 15:22:18

+0

嘿史蒂夫,看起來我們真的很接近解決這個問題。這次下面的代碼給我帶來了麻煩 - 「對於Sld.Shapes中的每個Sh」,它說 - 「運行時錯誤13,類型不匹配」。謝謝你的幫助。 – 2014-12-17 09:00:53