I am trying to create a Sub process which create a bunch of image and group it multiple times. For First loop everything runs OK VBA Code runs as expected, On Second run VBA gives the error "Grouping is disable for selected shapes"
Sub PPT_AddShape14
x = 8 * (i - 1) + 170 * (i - 1)
y = 0
Set sh1 = vslide.Shapes.AddShape(msoShapeRectangle, x + 8, y + 8, 170, 170)
Set sh2 = vslide.Shapes.AddShape(msoShapeRectangle, x + 8, y + 178, 170, 30)
Set sh3 = vslide.Shapes.AddShape(msoShapeRectangle, x + 8, y + 208, 170, 190)
vslide.Shapes.Range(Array("sh1", "sh2", "sh3")).Group.Name = Str(x)
Set Tiles = vslide.Shapes(Str(x))
End Sub
It's always a good idea to put Option Explicit at the top of every module and to properly declare your variables. But the issue with your code is that Range takes the NAMES of shapes as arguments, not strings that happen to match the names you've given the object variables you're using. This works: