繁体   English   中英

在不使用.type属性的情况下计算PowerPoint中的形状组

[英]Count the group of shapes in powerpoint without using .type property

我测试过的脚本是从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属性轻松实现,但是该属性在某些具有许多分组形状的演示文稿中无济于事。

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

您已经在问题中提到不想使用.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

请记住,如果在组中有组,这将无法给出准确的结果。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM