Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Oct 2004
    Location
    USA
    Posts
    223
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Add to shaperange (2000 sp3)

    I'm trying to write VBA code to work with shapes and I'm having trouble grouping them. I can find lots of information about these statements:
    ActiveSheet.Shapes.Range(Array("Shape1", "Shape2", "Shape3")).Select
    Selection.ShapeRange.Group.Select
    to group them but I can't hard code the names like that in my code. I need to be able to handle differing numbers of shapes and differing names. I tried building an array of the shape names and using that in place of the array function like this:
    ActiveSheet.Shapes.Range(aryShpNms).Select
    but I couldn't get it to work. Failing that, I was wondering if there is a way to add another shape to the selection? It would help if I could select the first one and then add to the selection in a loop with something like this:
    ActiveSheet.Shapes.Range(Array(Selection.ShapeRang e, strShpNm)).Select
    but I couldn't get this to work either.
    Does anyone have any ideas on this? I'd really appreciate any help at all.
    Thanks

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Add to shaperange (2000 sp3)

    You can use code like this:

    Dim aryShpNms() As Variant
    Dim n As Integer
    Dim i As Integer
    ...
    n = 3
    ReDim aryShpNms(1 To n)
    For i = 1 To n
    aryShpNms(i) = ...
    Next i

    ActiveSheet.Shapes.Range(aryShpNms).Group

  3. #3
    3 Star Lounger
    Join Date
    Oct 2004
    Location
    USA
    Posts
    223
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Add to shaperange (2000 sp3)

    Hans,
    You are the greatest! I tried changing my code to match yours and I couldn't get it to work so I copied yours and put it in a new procedure and it worked perfectly! I see now that defining the array as Variant is key, though I don't know why. Thanks so much for your help!
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •