View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Cannot activate a chart on a sheet

Comments in line -

"Farooq Sheri" wrote in message
...
I have a embedded chart (there is only one chart) on a sheet. I tried

naming
it with

ActivesSheet.ChartObjects(1).Name = "chart 1"

Question 1: did the above statement name the chart object or the chart
contained within the chart object?


It should do if you amend the typo ActivesSheet to ActiveSheet and no other
chart on the sheet with that name (subject protection).

Using a macro I tried to activate the chart with the command

Worksheets(2).ChartObjects(1).Activate

this however did not activate the chart.

If however I change the command to

Worksheets(2).ChartObjects("Chart 75").Activate

the chart is activated ("Chart 75" is the name of the chart as it appears

on
the top of the widow that pops up if you right click on the chart and

select
Chart Window).


Not sure why ChartObjects(1) fails but ChartObjects("Chart 75") works,
there's obviously at least one chartobject on the sheet.

This name (on the Chart Window) changes everytime the chart is
redrawn.


You mean each time you deleate & recreate a chart. The number will increment
to the total number of objects that have 'ever' been added to the sheet. The
counter is only reset if the wb & sheet is saved with no objects.

Question 2: How can I select the chart on the desired sheet?


Need to activate the sheet first.

Question 3: Can I somehow extract the name as it appears on the Chart

Window?

Activesheet.Chartobjects.Chart.Name returns 'sheetname chartname' which will
be prefixed with the sheetname (the chartwindow also includes [wb-name]).
It's actual name though for referencing purposes is -
Activesheet.Chartobjects(1).Name or ActiveChart.Parent.Name

I do not know if it has anything to do with it, but the chart on sheet 2

was
placed as a result of a comboBox_Change code. ComboBox is on sheet 1.


Not directly related

Regards,
Peter T