PDA

View Full Version : Trying to rename individual shapes within a duplicated group.



Spielberg
08-22-2020, 09:41 AM
Hello all Excel gurus...

I create a lot of puzzles and games. Each game has an answer key. This particular puzzle has a duplicated grid of grouped shapes.

Normally, I'd write a quick VBA program to rename everything for me, but due to the haphazard nature of this particular one, I couldn't do that.

There are 433 individual groups of 3 shapes each, for a total of 1,299 shapes that I renamed manually. No big deal. Just don't want to do it again (my carpal tunnel is bad enough.)

To create the puzzle, I do not need to access the group, only the individual shapes within the group. Works perfectly, since I don't care what the group names are - Excel named them whatever it wanted to.

For the answer key, those 433 groups were duplicated, and using my coordinate system, I am renaming the groups (the 3 shapes within will still be the same.)

Using a leading zero XY coordinate system, We can call the first one Group_0101 with Shape1_0101 Shape2_0101, and Shape3_0101 within it.

Is it possible to access shapes within a named group? I tried using .Item(x)

It's too bad that when Excel duplicates shape names, it can't act on all that have teh same name when you make a change.

I'm sorry I am not the best at describing things, I hope this wasn't too confusing.

Thank you in advance to anyone who can help!

Mike

SamT
08-22-2020, 01:11 PM
I'm not too familiar with Shapes, But usually when Excel duplicates names, it ties those names to the Sheet.Name. Something like


Sheets("Some Copy").Shapes("ShapeName").BlahBlah
Or

With Sheets("Some Copy")
.Shapes("ShapeName") BlahBlah
End With

Wherein "ShapeName" is the same on two different sheets

Use *Range.Group.GroupItems(index) to access individual shapes in a group

Paul_Hossler
08-22-2020, 02:09 PM
Maybe this will get you started

I didn't understand the coordinate system, renaming, etc.



For the answer key, those 433 groups were duplicated, and using my coordinate system, I am renaming the groups (the 3 shapes within will still be the same.)

Using a leading zero XY coordinate system, We can call the first one Group_0101 with Shape1_0101 Shape2_0101, and Shape3_0101 within it.


Post more details and a sample workbook if you need anything else



Option Explicit


Sub test()
Dim oShape As Shape, oSubshape As Shape


For Each oShape In ActiveSheet.Shapes

Debug.Print oShape.Name

If oShape.Type = msoGroup Then
For Each oSubshape In oShape.GroupItems
Debug.Print oSubshape.Name
Next
End If
Next
End Sub





26996


With some renaming I guessed at





Sub test2()
Dim ws As Worksheet
Dim oShape As Shape, oSubshape As Shape


Dim n1 As Long, n2 As Long


For Each ws In ActiveWorkbook.Worksheets
For Each oShape In ws.Shapes
n1 = n1 + 1

oShape.Name = "Shape " & Format(n1, "0000")

n2 = 0
If oShape.Type = msoGroup Then
For Each oSubshape In oShape.GroupItems

n2 = n2 + 1

oSubshape.Name = "Shape " & Format(n1, "0000") & "-" & Format(n2, "0000")

Next
End If
Next
Next


End Sub


26997