To delete the shapes on a PowerPoint slide using VBA.
Here we had 2 command buttons on the slide, one for adding the shapes and another one for deleting the shapes.Once we click on the delete button, all the auto shapes will be deleted, while command buttons will not be deleted.
We have used a slide similar to one which is shown below.We shall click on delete button as shown below.
Once we click on the delete button, all the shapes will be deleted.
- Created a command button on the slide 1 and change the caption to “Delete Shapes”.
- In code for deleting shape, we loop through each shape in slide 1
- If shape type is auto shape then delete that shape on slide 1
Private Sub DeleteShapes_Click() Dim shpCount As Double Dim osld As Shapes Set osld = ActivePresentation.Slides(1).Shapes shpNumber = 1 'Deleting only auto shapes in slide 1 For shpCount = 1 To osld.Count If ActivePresentation.Slides(1).Shapes(shpNumber).Type = msoAutoShape Then ActivePresentation.Slides(1).Shapes(shpNumber).Delete Else shpNumber = shpNumber + 1 End If Next shpCount End Sub
Similar approach can be applied to delete shapes from all the slides or from any specific slides.
Post you may like