• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Rename Chart/Shape Object Using VBA

Girish7919


Firstly, Welcome to the Chandoo.org Forums


It will be like:


ActiveSheet.Shapes("Old Chart Name").Name = "New Chart Name"
 
Hi Hui,


Thanks for reply.


But i am creating Chart/Shape through VBA, we can't know "Old Chart Name" at that instance.

Can u help me here.
 
Hi Girish,


I assume you would like to add chart/shape and name it with specific naming convention like MyChart1, MyChart2, or MyShape1, MyShape2 etc., whereby if the name of the chart/shape is starting with "My" then we can assume safely that it has been renamed by you.


Now having said that, try the following code:

dim iCounter as Integer

For Each pic In ActiveSheet.Shapes

iCounter = iCounter + 1

'code to check if the chart/shape is already renamed or no

IF VBA.InStr(1, pic.Name, "My") = 0

' True indicates the chart/shape's name was not starting with "My"

' You can rename to your naming convention

pic.name = "MyShape" & iCounter

End If

Next pic


Hope this solves your issue.


Regards,

Prasad DN.

PS: For Each pic In ActiveSheet.Shapes code traverses all shapes in the worksheet like chart, shapes, cliparts and wordart
 
Back
Top