ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Names of Shapes (https://www.excelbanter.com/excel-programming/314489-names-shapes.html)

Michael Singmin

Names of Shapes
 
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

Frank Kabel

Names of Shapes
 
Hi
try

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

--
Regards
Frank Kabel
Frankfurt, Germany

"Michael Singmin" schrieb im Newsbeitrag
...
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



Tom Ogilvy

Names of Shapes
 
Sheet1.Shapes(1).Select
Sheet1.Shapes(2).Select

Why not rename one of them?

--
Regards,
Tom Ogilvy

"Michael Singmin" wrote in message
...
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




Frank Kabel

Names of Shapes
 
[...]

Why not rename one of them?


Hi Tom
that solution is probably too simple <vbg

nice weekend
Frank

Dave Peterson[_3_]

Names of Shapes
 
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.

Michael Singmin wrote:

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


--

Dave Peterson


Michael Singmin

Names of Shapes
 
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

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


Dave Peterson wrote:

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.

Michael Singmin wrote:

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




All times are GMT +1. The time now is 06:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com