Delete the shapes on a PowerPoint slide using VBA

Delete shapes from slide using vba in power point

Objective

To delete the shapes on a PowerPoint slide using VBA.

Approach

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.

 

Delete shapes from slide using vba in power point

 

Once we click on the delete button, all the shapes will be deleted.

 

Delete shapes from slide using vba in power point

 

Steps

  1. Created a command button on the slide 1 and change the caption to “Delete Shapes”.
  2. In code for deleting shape, we loop through each shape in slide 1
  3. If shape type is auto shape then delete that shape on slide 1

 

Code

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

 

Note

Similar approach can be applied to delete shapes from all the slides or from any specific slides.

Post you may like

Add or modify title in a PowerPoint slide using VBA by user input box

 

 

1 comment on “Delete the shapes on a PowerPoint slide using VBA

Comments are closed.