Hi All. I have a Powerpoint slide, that has a Chart Object on it now. I have different lines and text boxes in there. I currently manually paste a chart from Excel, into this Chart Object in Powerpoint, by clicking on the chart Object, and then just hitting Ctrl-P. I do this, because then the lines and text boxes are on top of my pasted chart, so all things are visible. So, I want to automate this process in VBA. I have all code in place to copy the chart, and paste it into the slide. However, I cannot seem to figure out how to paste into the actual Chart Object on that slide. Basically, here is what I have. I can grab a specific chart from Excel. Then open Powerpoint, and loop through the shapes on the slide, until I find my Chart Object. At that point, I would like to paste INTO that object.
Somehting like ppShape.PasteSpecial xxxx. But PasteSpecial is not available to the ppShape object. Any thoughts or ideas? Thanks all.
Somehting like ppShape.PasteSpecial xxxx. But PasteSpecial is not available to the ppShape object. Any thoughts or ideas? Thanks all.
Code:
Sub PasteGraphsToPowerpoint()
Dim ppApp As PowerPoint.Application
Dim ppSlide As PowerPoint.Slide
Dim ppOb As Object
Dim ppShape As PowerPoint.Shape
'Look for existing instance
On Error Resume Next
Set ppApp = GetObject(, "PowerPoint.Application")
On Error GoTo 0
'Create new instance if no instance exists
If ppApp Is Nothing Then Set ppApp = New PowerPoint.Application
'Add a presentation if none exists
'If ppApp.Presentations.Count = 0 Then ppApp.Presentations.Add
If ppApp.Presentations.Count = 0 Then ppApp.Presentations.Open "MyPresentation.pptx"
'Make the instance visible
ppApp.Visible = True
Set ppSlide = ppApp.ActiveWindow.View.Slide
ActiveSheet.ChartObjects("Chart 7").Select
ActiveChart.ChartArea.Copy
For Each ppShape In ppSlide.Shapes
If ppShape.Name = "Chart 15" Then
ppShape.Select msoTrue
MsgBox "This is the shape I want to paste in!"
End If
Next
AppActivate ("Microsoft PowerPoint")
Set ppSlide = Nothing
Set ppApp = Nothing
End Sub