简体   繁体   English

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

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

The script which I have tested is running from excel application, which will count the shapes of pictures and count of actual shapes (that is textbox,placeholder) .Below is the script which pops up messages with the count of pictures and shapes 我测试过的脚本是从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

The count of shapes and pictures are displayed perfectly But am unable to get the count of group of shapes, this can be easily achieved by .type=msogroup property however that property will not help me in some of the presentations which have many grouped shapes. 形状和图片的数量可以完美显示,但是无法获得形状组的数量,这可以通过.type = msogroup属性轻松实现,但是该属性在某些具有许多分组形状的演示文稿中无济于事。

Please help me to update the script by using name of the shapes likewise the above script 请像上面的脚本一样,通过使用形状名称来帮助我更新脚本

You've mentioned in your question that you don't want to use the .Type property w/o explaining the reason for this. 您已经在问题中提到不想使用.Type属性,而无需说明原因。 Since it gives you a direct way to do what you need, I'll mention that you can test the .Type of each oShp and if it's msoGroup, oShp.GroupItems.Count will give you the number of shapes in the group. 由于它为您提供了直接执行所需内容的方法,因此我将提及您可以测试每个oShp的.Type,如果是msoGroup,则oShp.GroupItems.Count将为您提供组中形状的数量。 For example, you could pass each shape to this function and sum the results as you go: 例如,您可以将每个形状传递给此函数,然后将结果汇总:

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

Bear in mind that this won't give accurate results if there are going to be groups within groups. 请记住,如果在组中有组,这将无法给出准确的结果。

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

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