PDA

View Full Version : Exporting charts as GIFs, help needed



sardaukar
05-25-2007, 10:14 AM
Hello all!

I have the following code :


Sub ChartPict_save()

Dim sFName As String
Dim Pict As Object
Dim ch
Dim i As Integer

i = 1

Sheets("Ocorr?ncias por Tipo").Select
For Each Pict In ActiveSheet.ChartObjects
Set ch = Pict.Chart
sFName = HTMLExportForm.exportPath & "graph" & i & ".gif"
ch.Export Filename:=sFName, FilterName:="GIF"
i = i + 1
Next

Sheets("Pivot Chart").Select
For Each Pict In ActiveSheet.ChartObjects
Set ch = Pict.Chart
sFName = HTMLExportForm.exportPath & "graph" & i & ".gif"
ch.Export Filename:=sFName, FilterName:="GIF"
i = i + 1
Next

Sheets("Indisponibilidade").Select
For Each Pict In ActiveSheet.ChartObjects
Set ch = Pict.Chart
sFName = HTMLExportForm.exportPath & "graph" & i & ".gif"
ch.Export Filename:=sFName, FilterName:="GIF"
i = i + 1
Next

Sheets("Tempo de Resposta").Select
For Each Pict In ActiveSheet.ChartObjects
Set ch = Pict.Chart
sFName = HTMLExportForm.exportPath & "graph" & i & ".gif"
ch.Export Filename:=sFName, FilterName:="GIF"
i = i + 1
Next

Sheets("Problemas").Select
For Each Pict In ActiveSheet.ChartObjects
Set ch = Pict.Chart
sFName = HTMLExportForm.exportPath & "graph" & i & ".gif"
ch.Export Filename:=sFName, FilterName:="GIF"
i = i + 1
Next

Set ch = Nothing

End Sub

It's a mix of 90% code I googled for and some personal customizations. I managed to export the charts on all my sheets, but not all of them. For example, if a sheet has 3 charts, it only dumps 1. I have another sheet with 3 and it only dumps 2 of them. How can this be? What makes the charts that are not being exported different?

Thanks for any help!

mdmackillop
05-26-2007, 12:51 PM
Can you post a sample file containing the referenced items?

sardaukar
05-26-2007, 05:56 PM
I'm afraid it would be useless, I import SharePoint data to generate them...

JonPeltier
05-28-2007, 11:36 AM
I would suggest two changes:

Dim Pict As Object
Dim ch

should be

Dim Pict As ChartObject
Dim ch As Chart

Also, set up your loop differently:

Dim iChtOb As Long
For iChtOb = 1 To ActiveSheet.ChartObjects.Count
Set ch = ActiveSheet.ChartObjects(iChtOb).Chart
' blah blah
Next

Now in fact you don't need Pict.