Mark
Mark

Reputation: 71

Grouping Shapes

I have created three shapes based on user inputs. The three shapes output what looks like a reel (flanges + drum). I want the shapes to be grouped so that when the user moves the shapes they will not have to select all three shapes individually.

In the code below, the first three lines create the overall shape. The last line is my failed attempt to get those shapes to be a group of shapes.

Any assistance with this issue would be much appreciated. Thank you.

Sub AddShapeReel()

Dim s As Shape
Dim s1 As Shape
Dim s2 As Shape
Dim ws As Worksheet
Dim shpgroup
Set ws = Sheets("Deck Layout")

'add a shape

Set s = ws.Shapes.AddShape(msoShapeRectangle, 50, 50, Cells(26, 4) * 2.142857, Cells(28, 4) * 2.142857)
Set s1 = ws.Shapes.AddShape(msoShapeRectangle, 50 - ((Cells(30, 4) * 2.142857 - Cells(26, 4) * 2.142857) / 2), 49, Cells(30, 4) * 2.142857, 1)
Set s2 = ws.Shapes.AddShape(msoShapeRectangle, 50 - ((Cells(30, 4) * 2.142857 - Cells(26, 4) * 2.142857) / 2), Cells(28, 4) * 2.142857 + 50, Cells(30, 4) * 2.142857, 1)
Set shpgroup = ws.Shapes.Range(Array(s, s1, s2)).Group

end sub

Upvotes: 0

Views: 840

Answers (1)

Marc
Marc

Reputation: 11613

The syntax generated by a recorded macro looks like a little like this after the shapes are created:

ActiveSheet.Shapes.Range(Array("Rectangle 2", "Rectangle 3")).Select
Selection.ShapeRange.Group.Select

Presumably you could adapt that by selecting and grouping your shapes, like this:

ActiveSheet.Shapes.Range(Array(s, s1, s2)).Select
Selection.ShapeRange.Group

I haven't had a chance to confirm it though.

Upvotes: 1

Related Questions