Delete charts from PowerPoint Slide using VBA Excel

delete charts from slide using VBA Excel


To delete the charts from PowerPoint slide using VBA Excel.


Here we have 1 bar chart, 1 pie chart, 1 command button, 1 rectangular shape on slide 1. We loop through each of these objects and when we find that the selected object is of chartĀ  type, then we delete it. Once we execute the VBA code, only charts are deleted, while other objects present on slide 1 remain intact.

delete charts from slide using VBA Excel

Below shown code is written inĀ  Excel macro file.
We have assigned the macro code to a command button in excel macro file, once we click on the command button, it opens up the PPT from local drive path and the remaining code is executed. This code will be executed for slide 1.

Below is the reference we need to add in excel macro file to execute this code.


delete charts from slide using VBA Excel


We have created a command button on excel macro file, which was allocated this VBA code.


delete charts from slide using VBA Excel




Sub DeleteChartOnPowerPointSlide()
Application.ScreenUpdating = False
Dim TargetPpt As PowerPoint.Presentation
Dim TotalShapesOnSlide As PowerPoint.Shapes

Dim ObjPowerPointApp As PowerPoint.Application
Set ObjPowerPointApp = CreateObject("PowerPoint.Application")
'Open PPT from local path
Set TargetPpt = ObjPowerPointApp.Presentations.Open("C:\Users\myusername\Desktop\macro\Test_ppt.pptx")
Set TotalShapesOnSlide = ObjPowerPointApp.ActivePresentation.Slides(1).Shapes
shpIndex = 1
'Looping through each shape on slide by using shape index
For shapeCount = 1 To TotalShapesOnSlide.Count
    If ObjPowerPointApp.ActivePresentation.Slides(1).Shapes(shpIndex).Type = msoChart Then
        shpIndex = shpIndex + 1
    End If
Next shapeCount
'Save and close the opened ppt
End Sub



delete charts from slide using VBA Excel



Post you may like

How to rename multiple folders using VBA Excel