View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Leith Ross[_2_] Leith Ross[_2_] is offline
external usenet poster
 
Posts: 128
Default find name of a chart

On Mar 14, 7:46 pm, inquirer wrote:
I am writing some vba code in Excel 2003 to use the histogram function
to make histograms of data in a number of different worksheets.
I would like to delete all existing charts in a worksheet and then
create a histogram and then modify its properties. I have:

Application.Run
"ATPVBAEN.XLA!Histogram",ActiveSheet.Range("$D$2:$ D$733") _
, ActiveSheet.Range("$K$2"), ActiveSheet.Range("$J$3:$J$21"),
False, False _
, True, False
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select
ActiveSheet.Shapes("Chart 1").ScaleHeight 2.98, msoFalse,
msoScaleFromTopLeft
ActiveChart.Legend.Select
Selection.Delete

If there is an existing chart in the worksheet, this fails at
ActiveSheet.ChartObjects("Chart 1").Activate

so I would like to know how to get the name of the chart created by the
histogram.

Could anyone help please?
Thanks
Chris


Hello Chris,

The new chart will always be the last one added to the collection.
Yoou can return the name like this...

N = ActiveSheet.ChartObjects.Count
ChrtName = ActiveSheet.ChartObjects(N).Name

Siincerely,
Leith Ross