ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   ChartObjects (https://www.excelbanter.com/excel-programming/307432-chartobjects.html)

Nick

ChartObjects
 
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

Jarek[_8_]

ChartObjects
 
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

--
Message posted from http://www.ExcelForum.com


Sean[_11_]

ChartObjects
 
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!


All times are GMT +1. The time now is 11:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com