Link to home
Start Free TrialLog in
Avatar of Dr.Abdulwahab Al-anesi
Dr.Abdulwahab Al-anesiFlag for Yemen

asked on

Export pivot chart to power point

How to Export pivot chart from access 2003 or 2007 to power point
Avatar of Kelvin Sparks
Kelvin Sparks
Flag of New Zealand image

The simplest way is to export the chart to a jpeg, then embed it into Powerpoint.
 
You can use code such as
.ChartSpace.ExportPicture "C:\Documents and Settings\Paul\Desktop\" & varName & ".jpg", "JPEG"  to export the desktop for use Paul (varName would have been a unique filename assigned via a txtbox for the graph.
 
Kelvin
make that Me.ChartSpace......
 
Kelvin
Hi, Here I gives one solution for export p'chart, but you have to place it in PPT manually...
Private Function ExportMyCharts() As Boolean
Const Path_SavedChart As String = "C:\"
Dim i As Long
Dim objSht As Worksheet

Set objSht = ThisWorkbook.Sheets(1)

If objSht.ChartObjects.Count < 1 Then
    ExportMyCharts = False
    Exit Function
Else
    ExportMyCharts = True
    For i = 1 To objSht.ChartObjects.Count
        objSht.ChartObjects(i).Chart.Export Path_SavedChart & "\" & i & ".gif"
    Next
End If
End Function

Open in new window

Avatar of Dr.Abdulwahab Al-anesi

ASKER

Kelvinspark;
I tried as below but did not work
Private Sub Command59_Click()

ChartSpace.ExportPicture "C:\Documents and Settings\aalanesi\Desktop\" & DPTCoverageUtilizationPivot & ".jpg", "JPEG"
End Sub

Can you correct if I am wrong
Me.ChartSpace, not chartspace - was a typo on my part. This assumes the graph is on the same forms as the command button.
 
Kelvin
Thanks Kelvin BUT It did not work May be there is a need of more details.
ASKER CERTIFIED SOLUTION
Avatar of Kelvin Sparks
Kelvin Sparks
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Note their is a special section for pivot charts
Kelvin
Dear Kelvin

Thanks to your support finally  I succeeded I used the following to export a pivot named as Non_Vaccine_Coverage_Pivot_Cahrt

Private Sub Command25_Click()
 Dim frm As Access.Form

    Set frm = Me.Non_Vaccine_Coverage_Pivot_Cahrt.Form
    frm.ChartSpace.ExportPicture "C:\Documents and Settings\aalanesi\My Documents\Non Vaccine coverage PivotChart.jpg", "JPEG"
End Sub
Great
 
I should have given the initial line in the first place.
 
Kelvin
Te code be low works in my PC bout not in other PCs,  What I should change to make the picture be exported to My Document folder of the current user?  

Private Sub Command25_Click()
 Dim frm As Access.Form

    Set frm = Me.Non_Vaccine_Coverage_Pivot_Cahrt.Form
    frm.ChartSpace.ExportPicture "C:\Documents and Settings\aalanesi\My Documents\Non Vaccine coverage PivotChart.jpg", "JPEG"
End Sub
I suspect the path to My Documents is failing, as it may well be hard coded to your name.
 
In a code module create the following lines
Declare Function SHGetFolderPath Lib "shfolder.dll" Alias "SHGetFolderPathA" (ByVal hwndOwner As Long, ByVal nFolder As Long, ByVal hToken As Long, ByVal dwReserved As Long, ByVal lpszPath As String) As Long
Private Const MY_DOCUMENTS& = &H5
Private Const MY_PICTURES& = &H27
Private Const HWND_CURRENT_WINDOW& = &H0
Then copy in the two functions in the code below
 
Then, in your form, use
Private Sub Command25_Click()
 Dim frm As Access.Form

Dim MyDocs As String
''Find the location of My Documents
MyDocs = GetFolderPath(MY_DOCUMENTS)  
    Set frm = Me.Non_Vaccine_Coverage_Pivot_Cahrt.Form
    frm.ChartSpace.ExportPicture MyDocs & "\Non Vaccine coverage PivotChart.jpg", "JPEG"
End Sub
 
Kelvin
 
Note, I got the functions etc from some other place in EE a year or so back when doing a similar project.


 

Private Function TrimNull(startstr As String) As String
   Dim i As Integer
   Dim char As String
   For i = Len(startstr) To 1 Step -1
      char = Mid$(startstr, i, 1)
      If Asc(char) = 0 Then
         TrimNull = Mid(startstr, 1, i - 1)
      End If
   Next
End Function

Private Function GetFolderPath(folder As Long) As String
   'declarations
   Dim buff As String
   
   'fill buffer with the specified folder item
   buff = Space$(256)
   If SHGetFolderPath(-1, folder, -1, &H27, buff) = 0 Then
      GetFolderPath = TrimNull(buff)
   End If
End Function

Open in new window

Dear Kelvin
I could not use or understand your last comments, can we keep in touch till we resolve it
What should I do to make it exported to any current user my document.

Or opt them to select the destination folder.
My last comment was code to return to you the path of the logged in users My Documents.
A simpler solution would be to have a common folder that all could use, that does not have their name in it (i.e. C:\GraphExport\)
It would be fairly simple to check that it exists, if not create it the export to it.
What's your thoughts on that?
Kelvin