Export report chart to jpg file (1 Viewer)

AndyV

Registered User.
Local time
Today, 04:49
Joined
Apr 24, 2008
Messages
32
I am building an app that will build customer based powerpoint presentations overnight based upon user requests. I am having difficulty with some charts they want in the presentations. I found some code that will export a form chart as a jpg file, but from the open form. I need to loop through a set of reports, and if the report contains data, export the report chart to a jpg, that I can then insert into a powerpoint slide created using vba. The form based syntax is as follows:

Private Sub cmdExportGraph_Click()
'=============================================
' Purpose: Export Graph
' E-Mail: Graeme Dot Wilson AT nationsbank Dot co Dot uk
' Programmer: Graeme Wilson
'=============================================
On Error GoTo cmdExportGraph_Click_Err
Dim strErrMsg As String 'For Error Handling
Dim oleGrf As Object
Dim strFileName As String
Dim strFilter As String
Dim lngFlags As Long

Set oleGrf = Me.OLEchart.Object

strFileName = ahtCommonFileOpenSave(Flags:=lngFlags, InitialDir:="C:\", _
Filter:="JPEG Files (*.jpg)", FilterIndex:=1, DefaultExt:="jpg", FileName:="MyGraph", _
DialogTitle:="Save the Graph", OpenFile:=False)

oleGrf.Export FileName:=strFileName
MsgBox vbCrLf & "The Chart " & strFileName & " has been exported", _
vbInformation + vbOKOnly, "Chart Exported :"

cmdExportGraph_Click_Exit:
Set oleGrf = Nothing
Exit Sub

cmdExportGraph_Click_Err:
Select Case Err
Case 1004 ' Export Cancelled
Resume cmdExportGraph_Click_Exit
Case Else
strErrMsg = strErrMsg & "Error #: " & Format$(Err.Number) & vbCrLf & vbCrLf
strErrMsg = strErrMsg & "Error Description: " & Err.Description & vbCrLf
MsgBox strErrMsg, vbInformation, "cmdExportGraph_Click"
Resume cmdExportGraph_Click_Exit
End Select

End Sub

I need to replace the line referring to the form chart:

Set oleGrf = Me.OLEchart.Object

with a line that refers to a report chart that is not open. Does anyone know the syntax I should use?

Many thanks,

Andy
 

AndyV

Registered User.
Local time
Today, 04:49
Joined
Apr 24, 2008
Messages
32
Re: Export report chart to jpg file - SORTED

Done it. I was vastly overcomplicating it. This works like a charm:

Private Sub Report_Deactivate()

Dim oleGrf As Object
Dim strFileName As String

Set oleGrf = Me.OLEChart.Object

strFileName = Me.Name

oleGrf.Export FileName:=outJPGPath & strFileName & ".jpg"

End Sub

So all I do is loop through the reports, and open them and then close them. (outJPGPath is a global constant setting the root path for the exported jpg file)

Andy
 

HiTechCoach

Well-known member
Local time
Yesterday, 22:49
Joined
Mar 6, 2006
Messages
4,357
Glad you got it working! :)

Thanks for posting the solution!
 

Users who are viewing this thread

Top Bottom