M
mcjamyhamy
Hi,
I'm trying to use VBA to extract underlying data from charts in
powerpoint and paste it into excel, i.e from the underlying powerpoint
datasheet that feeds the chart.
I've found the macro below on the net which copies the data in each
chart/datasheet and slide in powerpoint. When you run the macro in
powerpoint and then go into excel and click on paste manually it works
(at least for the first datasheet it's copying).
Sub GetChartData1() 'copies data from sheet
Dim s As Shape 'gr As Graph.Chart
Dim gr As Object
Dim sl As Slide
'Copies data from datasheet in powerpoint
For Each sl In ActivePresentation.Slides
For Each s In sl.Shapes
If s.Type = msoEmbeddedOLEObject Then
'we have found an OLE object
'check if it's a graph
If s.OLEFormat.ProgID = "MSGraph.Chart.8" Then
'this might vary depending on what version you're using
'now get a handle on the graph object itself
Set gr = s.OLEFormat.Object
gr.Application.DataSheet.Cells.Copy
End If
End If
Next s
Next sl
End Sub
I've tried to adapt the macro so that it automatically pastes the data
into excel but this does not seem to work.
Hope someone can help.
Thanks,
Lucas
Sub GetChartData2() ' Adpated to paste data into excel
Dim s As Shape 'gr As Graph.Chart
Dim gr As Object
Dim sl As Slide
'Copies data from datasheet in powerpoint
For Each sl In ActivePresentation.Slides
For Each s In sl.Shapes
If s.Type = msoEmbeddedOLEObject Then
'we have found an OLE object
'check if it's a graph
If s.OLEFormat.ProgID = "MSGraph.Chart.8" Then
'this might vary depending on what version you're using
'now get a handle on the graph object itself
Set gr = s.OLEFormat.Object
gr.Application.DataSheet.Cells.Copy
'***** Extra code to automate pasting into excel but doesn't
work******
Workbooks("test.xls").Sheets("sheet1").Activate
Range("B1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
End If
End If
Next s
Next sl
End Sub
I'm trying to use VBA to extract underlying data from charts in
powerpoint and paste it into excel, i.e from the underlying powerpoint
datasheet that feeds the chart.
I've found the macro below on the net which copies the data in each
chart/datasheet and slide in powerpoint. When you run the macro in
powerpoint and then go into excel and click on paste manually it works
(at least for the first datasheet it's copying).
Sub GetChartData1() 'copies data from sheet
Dim s As Shape 'gr As Graph.Chart
Dim gr As Object
Dim sl As Slide
'Copies data from datasheet in powerpoint
For Each sl In ActivePresentation.Slides
For Each s In sl.Shapes
If s.Type = msoEmbeddedOLEObject Then
'we have found an OLE object
'check if it's a graph
If s.OLEFormat.ProgID = "MSGraph.Chart.8" Then
'this might vary depending on what version you're using
'now get a handle on the graph object itself
Set gr = s.OLEFormat.Object
gr.Application.DataSheet.Cells.Copy
End If
End If
Next s
Next sl
End Sub
I've tried to adapt the macro so that it automatically pastes the data
into excel but this does not seem to work.
Hope someone can help.
Thanks,
Lucas
Sub GetChartData2() ' Adpated to paste data into excel
Dim s As Shape 'gr As Graph.Chart
Dim gr As Object
Dim sl As Slide
'Copies data from datasheet in powerpoint
For Each sl In ActivePresentation.Slides
For Each s In sl.Shapes
If s.Type = msoEmbeddedOLEObject Then
'we have found an OLE object
'check if it's a graph
If s.OLEFormat.ProgID = "MSGraph.Chart.8" Then
'this might vary depending on what version you're using
'now get a handle on the graph object itself
Set gr = s.OLEFormat.Object
gr.Application.DataSheet.Cells.Copy
'***** Extra code to automate pasting into excel but doesn't
work******
Workbooks("test.xls").Sheets("sheet1").Activate
Range("B1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
End If
End If
Next s
Next sl
End Sub