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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert all charts in workbook to gifs 1

Status
Not open for further replies.

Magnus53

Programmer
Jul 25, 2002
73
CA
Hi everyone

I'm working on this little project but I need help with some VBA code I'm trying to write. I'm trying to convert all charts in a workbook to gif files. So what I have to do is go through each sheet and get the charts and convert them to gifs, then go to the next sheet and so on till I've gone through the entire workbook.

Now I can get the sheet count properly, but I'm having trouble getting the chart objects for that particular sheet. Can anyone offer some suggestions?

Thanks in advance.

 
activesheet.chartobjects.count
gives you the number of charts on that sheet. You access each one through

activesheet.chartobjects(i)
where i is between 1 and the number of charts.

Alternatively, you can use

for each Ch in activesheet.chartobjects
.. use Ch here to create gif ..

next Ch Rob
[flowerface]
 
Thanks for the response Rob,

This is what I have written, but it doesn't convert the charts, it never goes into the For Each myChart In ActiveSheet.ChartObjects statement.

Here is my code, please forgive the debug lines. Maybe someone can see what I'm doing wrong.

Dim worksheetCount As Integer
Dim myChart As ChartObject
Dim myWorkSheet As Worksheet
Dim allWorkSheets As Worksheets
Dim filename As String
Dim sheetCount As Integer
Dim loopCount As Integer
Dim sheetTitle As String

worksheetCount = ActiveWorkbook.Sheets.Count
Debug.Print ("Number of worksheets: " & worksheetCount)
loopCount = 0
For Each myWorkSheet In ActiveWorkbook.Worksheets
sheetCount = myWorkSheet.ChartObjects.Count
Debug.Print (myWorkSheet.Name & " Chart Count: " & sheetCount)
If sheetCount <> 0 Then
For Each myChart In ActiveSheet.ChartObjects
myChart.Export filename:=&quot;C:\data\excel\chartgifs\&quot; & test & &quot;.gif&quot;, FilterName:=&quot;Gif&quot;
Next myChart
End If
loopCount = loopCount + 1
Next myWorkSheet
Debug.Print (&quot;Loop Count: &quot; & loopCount)
End Sub
 
You don't get an error, just nothing happens? What are the values for sheetcount that get printed to the debug window?
That's odd. In any case, though, you'd need to use

myChart.chart.Export filename:=&quot;C:\data\excel\chartgifs\&quot; & test & &quot;.gif&quot;, FilterName:=&quot;Gif&quot;

Rob
[flowerface]
 
Ah yes, now I got it working, thank you for the help Rob.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top