Duplicate shape nmes

DeepButi

New Member
Joined
Jul 14, 2015
Messages
46
Office Version
  1. 365
Platform
  1. Windows
Hi all,
I have some shapes to which I assigned specific names.

Copy/Paste any of them creates a new shape with the same exact name (despite what here is discused). Manually or via VBA. Only un-renamed shapes copy/paste operations create unique names.

How can I know, in VBA context,, wich one to work with?
To rename it I would need to know its ID, but no way to get it. I mean, to get IDs I need to use sheets(MySheet),shape(SHAPE NAME).id ... and I have two shapes with the same name.

Any idea?

Thks
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
How can I know, in VBA context,, wich one to work with?
Maybe:
By position on the sheet. (Left and Top)​
By text contained in the form (TextFrame2.TextRange.Text)​
-----------------------------------------------------------------------

Knowing that when you copy a shape it gives you the same name, then copy the shape but with vba and immediately rename it with the specific name you want.

For example:
VBA Code:
Sub nombres()
  Dim n As Long
 
  n = ActiveSheet.Shapes.Count
 
  ActiveSheet.Shapes("Model").Copy
  ActiveSheet.Paste
  Selection.Name = "MyNewFigure " & n + 1
End Sub

🧙‍♂️
 
Upvote 0
Solution
Code:
old_ID = ActiveSheet.Shapes(MyShapeName).ID
' ... copy & paste
For Each nm In ActiveSheet.Shapes
    If nm.Name = MyShapeName and nm.ID <> old_ID Then
        nm.Name = NewShapeName
        Exit For
    End If
Next

Somehow weird :cry:. Any better idea?
 
Upvote 0
Maybe:
By position on the sheet. (Left and Top)​
By text contained in the form (TextFrame2.TextRange.Text)​
-----------------------------------------------------------------------

Knowing that when you copy a shape it gives you the same name, then copy the shape but with vba and immediately rename it with the specific name you want.

For example:
VBA Code:
Sub nombres()
  Dim n As Long
 
  n = ActiveSheet.Shapes.Count
 
  ActiveSheet.Shapes("Model").Copy
  ActiveSheet.Paste
  Selection.Name = "MyNewFigure " & n + 1
End Sub

🧙‍♂️
Nice! Didn't think the new object remains selected. It works, thks.
 
Upvote 1

Forum statistics

Threads
1,223,104
Messages
6,170,125
Members
452,303
Latest member
c4cstore

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top