Bartek
Bartek

Reputation: 93

Delete all Images on one Slide with VBA in PowerPoint

I want to delete only images on a slide with VBA in PowerPoint.

With the given code all shapes on the slide are being deleted.

Sub DeleteAllPictures()

ActivePresentation.Slides(1).Shapes.Range.Delete

End Sub

The Images are added with the following Code:

    Sub InsertPic_EAP()
  'Insert Picture
 ActivePresentation.Slides(1).Shapes.AddPicture FileName:="U:\Automatisierung\3D_Module\EAP.png", _
   LinkToFile:=msoTrue, _
   SaveWithDocument:=msoTrue, Left:=260, Top:=110, _
   Width:=270, Height:=250

 ActivePresentation.Slides(1).Shapes.AddPicture FileName:="U:\Automatisierung\Bilder_AP\EAP_01.png", _
   LinkToFile:=msoTrue, _
   SaveWithDocument:=msoTrue, Left:=620, Top:=220, _
   Width:=270, Height:=115

    End Sub

How do I modify the code to only select and delete the Images on the slide.

Upvotes: 3

Views: 1047

Answers (1)

Mikku
Mikku

Reputation: 6654

This code will work for you: Edit - For Linked Pictures

Sub DeleteAllPictures()

Dim shp As Shape

    For Each shp In ActivePresentation.Slides(1).Shapes

    If shp.Type = msoLinkedPicture Then
        shp.Delete
    End If

    Next

End Sub

Looping through all the shapes in the slide and deleting if it is a picture.

Upvotes: 2

Related Questions