【问题标题】:how to call an open powerpoint from excel vba如何从excel vba调用打开的PowerPoint
【发布时间】:2014-12-14 02:10:29
【问题描述】:

我试图从给定位置打开一个 ppt,并试图破坏 ppt 中的所有链接。打开 ppt 后,我​​无法从那里从 excel 调用 ppt,因此代码出错。给我错误的行如下 - “对于 ActiveWindow.Slides 中的每个 Sld” - 对象不支持此属性或方法。任何帮助将不胜感激。

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

【问题讨论】:

    标签: excel powerpoint vba


    【解决方案1】:

    您在 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
    

    【讨论】:

    • 您好史蒂夫,感谢您的回复。当我写下你提到的“Set Pres = PPT.Presentations.Open file”的声明时。我收到错误:“预期:语句结束”。对不起,如果我误解了你的解释。
    • 啊,对不起。应该设置 oPres=PPT.Presentations.Open(file)
    • 嘿史蒂夫,看起来我们真的接近解决这个问题了。这次下面的代码给我带来了麻烦 - “对于 Sld.Shapes 中的每个 Sh”,它说 - “运行时错误 13,类型不匹配”。感谢您的帮助。
    • 嗯。不确定;我觉得没问题。下一行可能会通过摇摆不定。改成If Sh.Type = 10 Then(10是msoLinkedOLEObject的值,Excel中可能没有定义)
    • 知道了........我使用变量 Sh 作为形状,当我使用这个变量 Sh 作为对象而不是形状时,它起作用了。谢谢。
    猜你喜欢
    • 2019-01-07
    • 1970-01-01
    • 2022-12-23
    • 2017-07-26
    • 2015-12-23
    • 2015-07-20
    • 2017-06-15
    • 1970-01-01
    • 2014-08-06
    相关资源
    最近更新 更多