How to group a shape set programmatically in excel 2007 vba?

I repeat the data on the spreadsheet and create shapes on the form sheet. Once the forms are created, I would like to group them programmatically. However, I cannot understand the correct syntax. There are forms selected, and if I press the group button, they will be perfectly grouped. However, with the following code, I get

Runtime Error 438 The object does not support this method or property.

I base this code on vba examples on the Internet - I'm not a strong vba programmer. What is the right way to do this? I am working with excel 2007 and switching excel versions is not an option.

problematic snippet:

Set shapeSheet = Worksheets("Shapes")
With shapeSheet
 Selection.ShapeRange.Group.Select
End With

Context:

Dim shapeSheet As Worksheet
Dim tableSheet As Worksheet
Dim shpGroup As Shape

Set shapeSheet = Worksheets("Shapes")
Set tableSheet = Worksheets("Electrical Tables")


With tableSheet
    For Each oRow In Selection.Rows
            rowCount = rowCount + 1
            Set box1 = shapeSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 50, 50 + ((rowCount - 1) * 14), 115, 14)
            box1.Select (False)
            Set box1Frame = box1.TextFrame
            Set box2 = shapeSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 165, 50 + ((rowCount - 1) * 14), 40, 14)
            box2.Select (False)
            Set box2Frame = box2.TextFrame
     Next
End With
Set shapeSheet = Worksheets("Shapes")
With shapeSheet
 Selection.ShapeRange.Group.Select
End With
+3
source share
3 answers

Excel 2010:

Sub GroupShapes()

    Sheet1.Shapes.SelectAll
    Selection.Group

End Sub

1 , .

:

Sheet1.Shapes.Range(Array(1, 2, 3)).Select

:

Sheet1.Shapes.Range(Array("Oval 1", "Oval 2", "Oval 3")).Select
+2

,

Set shpGroup = shapeSheet.Shapes.Range(Array(Box1.Name, Box2.Name)).Group

PS. , , , , ( ), , Range Range Shapes. , , .

+5

, ( ), "select.all", .

Creating a shaperange was not very easy. The easiest way is to simply scroll through the form objects (if you already know them) and select them, simulating "hold the ctrl key down" using the option "Replace: = False".

So here is my code:

For ix = 1 To x
    bShp(ix).Select Replace:=False
Next
ActiveWindow.Selection.ShapeRange.Group

Hope this helps, Kerry.

+2
source

All Articles