0

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

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.

Please help me to update the script by using name of the shapes likewise the above script

lifeinvba
  • 69
  • 1
  • 4
  • 18
  • 1
    How about using `TypeOf`... look at this: [Check whether shape is a group](https://www.pcreview.co.uk/threads/check-whether-shape-is-a-group.2745324/) – PeterT Dec 10 '17 at 20:28
  • @PeterT thank you for the link am unable to get **typeof** property to count the shapes of powerpoint presentation from excel vba application.I tried the below code but it throwed an error this member can only be access in group when shp = groupi 'Sub test10() Dim shp As Shape Dim sld As Slide Dim i As Variant Dim grps As Object For Each sld In ActivePresentation.Slides For Each shp In sld.Shapes Set grps = shp.GroupItems If grps Is Nothing Then Debug.Print shp.Name Else For Each grp In grps Debug.Print grp.Name Next grp End If Next shp Next sld End Sub` – lifeinvba Dec 11 '17 at 05:52
  • It's difficult to get a firm handle on the problem without understanding exactly what's in the PowerPoint. If you can upload or post an example slide deck to illustrate the problem it would help. – PeterT Dec 11 '17 at 14:46
  • @Peter thanks for your reply have researched and got some idea how to do it will post it here – lifeinvba Dec 16 '17 at 07:42

1 Answers1

0

You've mentioned in your question that you don't want to use the .Type property w/o explaining the reason for this. 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. 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.

Steve Rindsberg
  • 14,442
  • 1
  • 29
  • 34