I found a code how to make Powerpoint VBA Harvey balls
and I changed the last line to CommandBars.ExecuteMso ("ObjectsGroup")
instead of CommandBars.ExecuteMso ("ShapesCombine")
.
The first run of macro went fine, but when I run again (the first harvey ball was on slide) I had the error
Shapes (unknow member): Integer out of range. [#]is not in the valid range of [#] to [#]
on the line Set oshpR = sld.Shapes.Range(Array(shp1.ZOrderPosition, shp2.ZOrderPosition))
If the shapes combined into one - there is no error. It appears with the group set only. I need this shapes as the group set on one slide. And there could be multiple sets on the slide.
Can you, please, tell me who to fix it? I assume it could be a problem, because it can be a lot of another groups sets (not harvey balls) on the slide.
Thanks, Lena
Sub Test2()
Dim sld As Slide
Dim shp1 As Shape
Dim shp2 As Shape
Dim oshpR As ShapeRange
Set sld = Application.ActiveWindow.View.Slide
Set shp1 = ActivePresentation.Slides(1).Shapes.AddShape(msoShapeOval, 300, 100, 50, 50)
Set shp2 = ActivePresentation.Slides(1).Shapes.AddShape(msoShapePie, 300, 100, 50, 50)
Set oshpR = sld.Shapes.Range(Array(shp1.ZOrderPosition, shp2.ZOrderPosition))
CommandBars.ExecuteMso ("ObjectsGroup") End Sub