Grouping Shapes

M

MatP

Hi,

Just can't figure how to group shapes of a sheet..


something like:

For i = 1 To ActiveSheet.Shapes.Count

If Left(ActiveSheet.Shapes(i).Name, 6) = "Forme " Then AddtoGroup

Next i

I can do this:

ActiveSheet.Shapes.Range(Array("Shape1", "Shape2")).Select
Selection.ShapeRange.Group.Selec

But the "Array" part in my case is variable and I can't find how to pu
a variable instead of Array("Shape1", "Shape2")).

Thank
 
L

Leo Heuser

Hi Mat

Here's one way to do it:

Sub MakeShapeRange()
'Leo Heuser, 20 Nov. 2003
Dim Counter As Long
Dim NumShapes As Long
Dim NumShapesToUse As Long
Dim SelectShapes As ShapeRange
Dim ShapeName() As Variant

NumShapesToUse = 0

With ActiveSheet
NumShapes = .Shapes.Count

For Counter = 1 To NumShapes
If Left(.Shapes(Counter).Name, 6) = "Forme " Then
NumShapesToUse = NumShapesToUse + 1
ReDim Preserve ShapeName(1 To NumShapesToUse)
ShapeName(NumShapesToUse) = .Shapes(Counter).Name
End If
Next Counter

Set SelectShapes = .Shapes.Range(ShapeName)
SelectShapes.Select
End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top