Names of Shapes

M

Michael Singmin

Hello Group,

I created a drawing of 3 lines and grouped them.
I named the group Maxi
I copied and pasted Maxi to a different area.

Now there are 2 entities called Maxi

When I use
Sheet1.Shapes("Maxi").Select. The first original Maxi is selected

How do I select the 2nd one ?

Thanks,

Michael Singmin
 
F

Frank Kabel

Hi
try

dim oshape as shape
for each oshape in Sheet1.Shapes
if oshape.name="Maxi" then
'do something
end if
next
 
D

Dave Peterson

Did you copy them in code or manually?

If you did it manually, you can rename the copy of the group by selecting it and
typing the new name in the name box.

If you did it in code, you can use something like:

Option Explicit

Sub testme()

Dim myLine1 As Shape
Dim myLine2 As Shape
Dim myLine3 As Shape
Dim myGroup As Shape
Dim myNewShape As Shape

With ActiveSheet

Set myLine1 = .Shapes.AddLine(271.5, 127.5, 318.75, 186#)
Set myLine2 = .Shapes.AddLine(240.75, 135#, 336.75, 180#)
Set myLine3 = .Shapes.AddLine(231#, 156#, 372.75, 169.5)

Set myGroup = .Shapes.Range(Array(myLine1.Name, _
myLine2.Name, myLine3.Name)).Group

myGroup.Name = "maxi"

Set myNewShape = myGroup.Duplicate
With .Range("a1:c9")
myNewShape.Top = .Top
myNewShape.Left = .Left
myNewShape.Width = .Width
myNewShape.Height = .Height
End With
myNewShape.Name = "maxi2"

End With
End Sub


You can also get the last shape you added with something like:

Option Explicit

Sub testme()

Dim myLine1 As Shape
Dim myLine2 As Shape
Dim myLine3 As Shape
Dim myGroup As Shape
Dim myNewShape As Shape

With ActiveSheet

Set myLine1 = .Shapes.AddLine(271.5, 127.5, 318.75, 186#)
Set myLine2 = .Shapes.AddLine(240.75, 135#, 336.75, 180#)
Set myLine3 = .Shapes.AddLine(231#, 156#, 372.75, 169.5)

Set myGroup = .Shapes.Range(Array(myLine1.Name, _
myLine2.Name, myLine3.Name)).Group

myGroup.Name = "maxi"

myGroup.Copy
.Range("a1:c9").Select
.Paste

Set myNewShape = .Shapes(.Shapes.Count)
myNewShape.Name = "Maxi2"

End With
End Sub

activesheet.shapes.count will be the last shape you added.
 
M

Michael Singmin

Thanks to all the answers.

I was just surprised that Excel allowed 2 entities to have the same
name.

I learnt a lot from your other answers especially the code below.

Much appreciated

Michael Singmin

===============================================================
 

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