Link to home
Start Free TrialLog in
Avatar of Eric Shen
Eric Shen

asked on

Deleting specific photos based on height and width in VBA powerpoint

Hi.

I am working with a 800 powerpoint slide document and was wondering if there was a way to delete images based off of their height and width dimensions.  The best I could find was someone's code deleting all images.  I was wondering if it is possible to tweak it as I am not that versed in VBA powerpoint.  Thanks:


Sub delete()
Dim osld As Slide
Dim I As Integer
    For Each osld In ActivePresentation.Slides
    For I = osld.Shapes.Count To 1 Step -1
        If osld.Shapes(I).Type = msoPicture Then osld.Shapes(I).delete
    Next I
    Next osld

End Sub
ASKER CERTIFIED SOLUTION
Avatar of Jamie Garroch (MVP)
Jamie Garroch (MVP)
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Eric Shen
Eric Shen

ASKER

Still not working properly.  I adjusted the dimensions for shapes with a height of 1.69" and 2.86" but could have definitely messed up that part.  The error message now becomes that Shapes in Shapes(I).delete is not defined?  Thanks for the help!
----Edit:  Bush league move and forgot a period.  It works!  Thanks so much Jamie! -------
Sub delete()
Dim osld As Slide
Dim I As Integer
    For Each osld In ActivePresentation.Slides
    For I = osld.Shapes.Count To 1 Step -1
       With osld
        If .Shapes(I).Type = msoPicture Then
            If .Shapes(I).Width = 1.69 * 72 And .Shapes(I).Height = 2.86 * 72 Then .Shapes(I).delete
        End If
      End With
    Next I
    Next osld

End Sub
Ah ha. I forgot to mention the conversion from points to inches (or cm for metric folk) but see you know about the magic number 72. Glad it worked for you. If you're happy with the solution, feel free to close off the question. Thanks :-)