0

I wrote a vba macro for PowerPoint. All works well but I miss one step.

So far my macro ends by selecting a certain group of shapes on a slide. After it finishes I go back to PowerPoint and use the "Group" button to make a group out of the selected shapes.

How can I use this Micorsoft Group function in my code. I only manage to group all shapes on a slide to one group or I get an error.

I have tryed: ActivePresentation.slide(1).shapes.selected.group but that doesn't work.

I have read this:

How do I group a set of shapes programmatically in excel 2007 vba?

but several names of shapes are identical, so that doesn't really work. And I do not know how to store the indexnumber of a shape into a variable - which would be a second option to solve my problem.

Basically the Microsoft own functions does exactly what I would need now, right? I takes the shapes that are selected and groups them to a group. can I just call this function within my macro?

Many thanks for any help.

Community
  • 1
  • 1
DrS.
  • 67
  • 2
  • 12

2 Answers2

1

If you've got the shapes selected, then this should do it:

Activewindow.Selection.ShapeRange.Group

Steve Rindsberg
  • 14,442
  • 1
  • 29
  • 34
0
ActivePresentation.Slides(1).Shapes.Range(Array(2, 3, 4)).Group
ActivePresentation.Slides(1).Shapes.Range(Array("this", "that", "other")).Group
ActivePresentation.Slides(1).Shapes.Range(Array("this", 42, 3)).Group
GSerg
  • 76,472
  • 17
  • 159
  • 346
  • Many thanks for your answer. But it is not really what I am searching for. See my code below. After the code the selected shapes should be grouped. `code` For Each Shape In ActivePresentation.Slides(SlideNumber).Shapes For l = LBound(Group) To UBound(Group) If Shape.Id = Group(l) Then If l = 1 Then Shape.Select Else Shape.Select Replace:=False End If End If Next l Next `code` – DrS. Aug 02 '15 at 20:50
  • On the other hand: If I need those index numbers [Array(2, 3, 4) - in your example] how can I access or store them to an array? I understood that they are NOT identical with the Shape.ID and NOT identical with the Zordernumber. Now while iterating through the shapes - as in above comment - can I somehow say: NewArrayXY(l) = Shape.indexnumber? Then I would be able to refer to that. But I haven't found a way to do so. Many thanks for further help. – DrS. Aug 02 '15 at 21:03
  • This is what you are searching for because you [don't want to select things](http://stackoverflow.com/q/10714251/11683) when you work with things. The `ShapeGroup` selects shapes by name or by index. You seem to create shapes and store their `Id`s in the array `Group` - just store the `Name`s instead, then call `ActivePresentation.Slides(1).Shapes.Range(Group).Group`. Two shapes cannot have identical names, trying to set a duplicated name raises the error number 70. – GSerg Aug 02 '15 at 21:10