Results 1 to 2 of 2
Thread: Embedded Charts (XL2002-SP1)
2005-07-11, 12:47 #1
- Join Date
- May 2002
- Johannesburg, Gauteng, South Africa
- Thanked 0 Times in 0 Posts
Embedded Charts (XL2002-SP1)
Following on from where Hans last helped me to get a class module sorted out to easily automate the creation of embedded charts in a workbook, I'm now stuck on a seemingly trivial issue.
When I create charts from code, I would like to name them appropriately for future reference. For example, each time I process a set of data, I would like to delete a certain chart (of known name!) if it exists, process the data and then recreate the chart with all it's appropriate new titles, legend, formatting, etc.
I've tried some code at the time the chart is created, but it don't seem to be able to set the name property of a chart object.
Selecting a chart and running the following code reads and prints the chart name to the immediate window, but fails on the name method.
<font color=red>Sub RenameChart()
ActiveChart.Name = "Lab Results"
End Sub</font color=red>
The error message is "Method 'Name' of object '_Chart' failed."
Maybe I should be using a ChartObject object or a Shape object or something to refer to the chart at a later stage ?
Could someone please tell me what I'm missing here ?
2005-07-11, 13:08 #2
- Join Date
- Mar 2002
- Thanked 30 Times in 30 Posts
Re: Embedded Charts (XL2002-SP1)
Use the ChartObjects collection:
ActiveSheet.ChartObjects(1).Name = "Lab Results"
or use a ChartObject variable:
Dim cht As ChartObject
Set cht = ActiveSheet.ChartObjects.Add(100, 100, 300, 200)
cht.Name = "Lab Results"