Assign Name to a shape

bbran19

New Member
Joined
Jan 30, 2012
Messages
49
Office Version
  1. 365
Platform
  1. Windows
I have a macro which, among other things, draws a smiley face ( :cool: ) from the Insert + Shapes menu after a positive event.

I have a reset all button to remove the data generated by the previous macro AND remove the smiley face.

However, the smiley face keeps changing name from similey face 25, then 26 and so on. So the macro cannot delete it.

I have tried renaming the face )ALT + F10) and in the NAME BAT which works temporarily until the reset macro runs. The the name of the smiley face keeps changing name.

I need a macro that will change the reference name so the shape can be deleted with a reset macro.

Any thoughts appreciated.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
This code will insert a standard smiley face at the active cell and name it 'MySmiley'.
Code:
Sub InsertSmiley()
Dim sh As Shape

    With ActiveCell
        Set sh = .Parent.Shapes.AddShape(msoShapeSmileyFace, .Left, .Top, 20, 20)
    End With
    
    sh.Name = "MySmiley"

End Sub
 
Upvote 0
This will delete all shapes that begin with the name "Smiley Face"

Code:
    Dim shp As Shape
    For Each shp In ActiveSheet.Shapes
        If shp.Name Like "Smiley Face*" Then shp.Delete
    Next shp
 
Upvote 0
Thank you AlphaFrog. That did the trick. Thankyou Norie. I have another sheet where that will work well. Your time is appreciated.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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