0

我测试过的脚本是从 excel 应用程序运行的,它将计算图片的形状和实际形状的数量(即文本框、占位符)。下面是弹出带有图片和形状数量的消息的脚本

Sub countshapes()
Dim strname As String
Dim thisslide As Long
Dim strshape() As String

-----Count the number of slides in presentation 

For thisslide = 1 To ActivePresentation.Slides.count

With ActivePresentation.Slides(thisslide)
ReDim strshape(0 To 0)

For Each oshp In .Shapes

If InStr(1, oshp.Name, "Picture") > 0 Then
ReDim Preserve strshape(0 To a)
strshape(a) = oshp.Name
a = a + 1

Else

ReDim Preserve strshape(0 To d)
strshape(d) = oshp.Name
d = d + 1
End If

Next oshp
End With
Next
MsgBox a
MsgBox d

形状和图片的数量完美显示但是我无法获得形状组的数量,这可以通过 .type=msogroup 属性轻松实现,但是该属性在某些具有许多分组形状的演示文稿中对我没有帮助。

请帮助我通过使用形状的名称来更新脚本,就像上面的脚本一样

4

1 回答 1

0

您在问题中提到您不想使用 .Type 属性而没有解释原因。由于它为您提供了执行所需操作的直接方法,因此我将提到您可以测试每个 oShp 的 .Type,如果它是 msoGroup,oShp.GroupItems.Count 将为您提供组中的形状数量。例如,您可以将每个形状传递给此函数并在执行过程中对结果求和:

Function CountGroupShapes(oSh As Shape) As Long
    If oSh.Type = msoGroup Then
        CountGroupShapes = oSh.GroupItems.Count
    Else
        CountGroupShapes = 1
    End If
End Function

请记住,如果组内有组,这不会给出准确的结果。

于 2017-12-12T19:03:21.183 回答