I am writing VBA code to copy paste chart from excel to PowerPoint. My code would first delete the existing chart from the PowerPoint slide before copy pasting the chart from excel.
Unfortunately some of charts are named as “Content Placeholder xx” in PowerPoint due to which existing chart in presentation wouldn’t get deleted. Since content placeholder can be table/ ready-made shape /chart, how can I test if content place holder is chart or some other shape?
Any guidance will be appreciated
Sub Powerpoint_Slide_MoveChart()
'// General declaration
Dim ppt As PowerPoint.Application
Dim ActiveSlide As PowerPoint.Slide
Dim Cht As ChartObject
Dim i As Integer
'// Set powerpoint application
Set ppt = GetObject(, "PowerPoint.Application")
'// Check if more then single powerpoint open
If ppt.Presentations.Count > 1 Then
MsgBox "Please close all other powerpoints except the one you would like to puiblish."
Exit Sub
End If
'// Set active slide as slide 9
Set ActiveSlide = ppt.ActivePresentation.Slides(9)
ppt.ActiveWindow.View.GotoSlide (9)
Set Cht = ActiveSheet.ChartObjects("ChartSlide9")
'// Delete existing chart
For i = 1 To ActiveSlide.Shapes.Count
If Left(UCase(ActiveSlide.Shapes(i).Name), 5) = "CHART" Then
ActiveSlide.Shapes(i).Delete
Exit For
End If
Next i
End Sub