在Excel宏中使用Powerpoint Shape对象

时间:2014-09-30 11:14:42

标签: vba excel-vba powerpoint-vba excel

我正在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

1 个答案:

答案 0 :(得分:0)

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

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