2014-12-13 120 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