Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Chart Name 1

Status
Not open for further replies.

369852

Programmer
May 7, 2002
38
0
0
IE
Hi all,

I am creating a chart based on results each time a .xls sheet is opened. This chart can be positioned in different places each time so i need to clear any existing chart before inserting the new one. As i understand it i must have the name of the chart to do this. Can anyone tell me how to get the name of the chart and if i can set the chart name myself?

Thanks in advance
 
1st select chart


find name:
chartname=ActiveChart.name



set name:
ActiveChart.name="Insert name here"



please note i havent tested this fully- but try it and maybe it might inspire you

let me know how u get on
 
forgot to say-- if using variable as chartnname:



ActiveChart.name=variable

hope this is ok
 
If you have only 1 chart on your sheet then
Activesheet.chartobjects(1).name

will return the name of the chart (so you can delete it)

To name a chart, after you have created it, use:
With Activechart
.name = "YourNameHere"
end with

If you do this as part of the chart creation, when you come to deleting it, all you will need is
Activesheet.chartobjects("Chartname").delete

HTH Rgds
~Geoff~
 
Thanks mrjakevisitor .

Now when i add the chart, i give it a name
Charts.Add
ActiveChart.Name = "test"

and then when clearing the sheet i have
ActiveSheet.ChartObjects("test").Activate
ActiveChart.ChartArea.Select
ActiveWindow.Visible = False
Selection.Delete

but i get an error on the line: ActiveSheet.ChartObjects("test").Activate

saying
"unable to get ChartObjects property of the worksheet class"

is this to do with the name or something else

Thanks

 
ActiveSheet.ChartObjects("test").Activate should read



ActiveSheet.Chart("test").Activate
 
No no no no - You must use the same syntax for naming and activating and deleting - you can't use Activechart.anme =
and then
Activesheet.chartobjects("test").activate
They're 2 seperate things

The CHARTS collection refers to CHARTSHEETS - the CHARTOBJECTS collection refers to embedded charts - decide which you're using and go with the appropriate syntax
Rgds
~Geoff~
 
Ok I still get the error mentioned above when i put in either
ActiveSheet.Chart("test").Activate
or

Activesheet.chartobjects(1).name

any ideas
 
What is your ACTIVEsheet - if the sheet doesn't have a chart, you'll get that error. Maybe you should reference the sheet by name
Sheets("Sheetname").chartobjects(1).name
Rgds
~Geoff~
 
this is probly wrong again but...


activeworkbooks.charts("test").activate
 
Thanks for all the help
Sheets("Sheetname").chartobjects(1).name
and
Sheets("Sheetname").chartobjects("Chartname").delete
worked great for me

Thanks again and until the next time....

:D
Jackie



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top