【问题标题】:Using Powerpoint Shape object in Excel Macro在 Excel 宏中使用 Powerpoint Shape 对象
【发布时间】:2015-02-18 10:52:43
【问题描述】:

我正在 Excel 中编写此 VBA 代码,它会在 powerpoint 文件中进行更改。除以下内容外,一切正常。 当我调用 FormatICTable 函数时,我得到一个运行时错误,即“类型不匹配”。在我看来,我作为第一个参数传递的那个形状对象正在造成问题。有什么建议吗?

Sub controlPPT()
    Dim PPT As Object
    Set PPT = CreateObject("PowerPoint.Application")
    Dim pres As Presentation
    With Application.FileDialog(1)
        .AllowMultiSelect = False
        .Show
        .Filters.Clear
        .Filters.Add "PPT files", "*.pptx"
        .FilterIndex = 1
        If .SelectedItems.Count > 0 Then
            PPT.Presentations.Open .SelectedItems(1)

            Dim sld As Slide

            Set pres = PPT.ActivePresentation
            For Each sld In pres.Slides
                sld.Select
                If sld.Shapes(1).TextFrame2.TextRange.Text = "Internal comparison" Then
                    Call FormatICTable(sld.Shapes(2), sld)
                End If
            Next

            pres.Save
            Set pres = Nothing
        End If
    End With
End Sub


Function FormatICTable(shp As Shape, sld As Slide)
    'My code here
End Function

【问题讨论】:

    标签: vba excel powerpoint


    【解决方案1】:

    所以,我自己得到了答案 Shape 对象应在函数签名中标记为 PowerPoint.Shape,而不是仅使用 Shape 类。

    Function FormatICTable(shp As PowerPoint.Shape, sld As Slide)
        'My code here
    End Function
    

    【讨论】:

    • @Steve,为什么会这样,我意识到有时,在处理该页面上的对象时,不选择幻灯片可能会阻止宏正常运行。
    猜你喜欢
    • 1970-01-01
    • 2017-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多