我测试过的脚本是从 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
请记住,如果组内有组,这将不会给出准确的结果。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句