ChartObjects

N

Nick

Hiya

I wish to populate a listbox with all the chartobjects
within a workbook.

I am using something like the following

Dim xlChart as ChartObject

For each XlChart in Thisworkbook.Worksheets.ChartObjects

Me.ListBox.AddItem xlChart.Name

Next xlChart

Unfortunately it doesn't recognise the ChartObjects
collection.

Can any see a solution?

Thanks in a advance for any help

Nick Shinkins
 
J

Jarek

Hi,
try something like following

Sub charts_names()
Dim i As Integer
Dim xlChart As ChartObject

For i = 1 To ActiveWorkbook.Worksheets.Count
For Each xlChart In Worksheets(i).ChartObjects
MsgBox xlChart.Name
Next xlChart
Next i

End Sub

Jare
 
S

Sean

I think that ChartObjects only applies to embedded charts i.e. those
whose location is a worksheet and not those that are seperate
chartsheets. You probably need to check for the existence of charts
under both possibilities .


'++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dim ws As Worksheet, ch As Chart, chOBJ As ChartObject

' get the names of all the chartsheets
For Each ch In ActiveWorkbook.Charts
Me.ListBox.AddItem ch.Name
Next ch

' get the names of all the embedded
For Each ws In ActiveWorkbook.Worksheets
For Each chOBJ In ws.ChartObjects
Me.ListBox.AddItem chOBJ.Chart.Name
Next chOBJ
Next ws
'++++++++++++++++++++++++++++++++++++++++++++++++++++++

----
Sean
"Just press the off switch, and go to sleep!"

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Top