Name Excel Charts using VBA


Posted by Richard Stainton on March 16, 2001 4:11 AM

I'm trying to name a chart created using VBA.

As there are many charts, which can be created in any order this workbook, I need a sure fired way of naming each chart uniquely as they are created.

I have tried everything I can think of.

Thanks in advance

Richard

Posted by Kristel k on March 16, 2001 7:25 AM

:a long time ago I found a solution for this but I can't find it anymore...
I remember it had something to do with the PARENT property. I hope this can already help you to find the solution

Posted by Dave Hawley on March 18, 2001 2:27 AM


Hi Richard

You can use Now converted to a long for unique naming, try this macro:

Sub NameAllCharts()
Dim Chrt As ChartObject
For Each Chrt In Sheet1.ChartObjects
i = 1 + 1
Chrt.Name = "Chart" & CLng(Now + i)
Next
End Sub

Dave


OzGrid Business Applications



Posted by Dave Hawley on March 18, 2001 2:29 AM

Oops, forgot to dimension a variable

Sub NameAllCharts()
Dim Chrt As ChartObject, i As Integer
For Each Chrt In Sheet1.ChartObjects
i = 1 + 1
Chrt.Name = "Chart" & CLng(Now + i)
Next
End Sub


Dave

OzGrid Business Applications