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.
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.
We have created a command button on excel macro file, which was allocated this VBA code.
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 ObjPowerPointApp.ActivePresentation.Slides(1).Shapes(shpIndex).Delete Else shpIndex = shpIndex + 1 End If Next shapeCount 'Save and close the opened ppt ObjPowerPointApp.ActivePresentation.Save ObjPowerPointApp.Windows(1).Close End Sub
Post you may like