Reputation: 1
I have many powerpoint files which have a picture at the top-right corner on every single slide. It is neither a master slide, NOT a custom layout shape.
They were pasted one by one to all slides.
I have some codes as below to remove all shapes(pictures) from slides, but how to locate the shapes(pictures) at a specific location of a slide?
For Each Slide In SlideList
Set sldTemp = ActivePresentation.Slides(Slide)
For lngCount = sldTemp.Shapes.Count To 1 Step -1
With sldTemp.Shapes(lngCount)
'----------Delete All shapes = picture----------
If .Type = msoPicture Then
.Delete
End If
End With
Next
Next
'-----------------------------------------
I am not very good at VBA for powerpoint coding, any suggestion is appreciated. thank you.
Upvotes: 0
Views: 341
Reputation: 1
thanks to Tim Williams very much.
The pilot codes run correctly on 3 Win10 x86 computers.
by the way, according to this saying
By default, the size of the new presentation in PowerPoint, is currently a widescreen type presentation, 13.333 inch by 7.5 inch. Mostly you will have 96 dots per inch (dpi) on your screen settings, so this means that a default PowerPoint presentation has a resolution of 1280 by 720 pixels.
though the top-left values set below can match exactly the top-right small logo(shape) in my powerpoint slide, and the same results from 3 different display ,and one of which is in low definition mode.
Sub DeleteAllTopRightShapes()
Dim sldTemp As Slide
Dim lngTemp As Long
Dim lngCount As Long
For Each sldTemp In ActivePresentation.Slides
For lngCount = sldTemp.Shapes.Count To 1 Step -1
With sldTemp.Shapes(lngCount)
If .Type = msoPicture Then
If .Top >= 0 And .Top < 60 And .Left >= 400 Then
.Delete
End If
End If
End With
Next
Next
MsgBox "Process complete!"
End Sub
Upvotes: 0
Reputation: 166331
You can check the position by looking at the Top and Left properties. You could also check the size if they're all the same size.
Eg:
If .Type = msoPicture Then
If .Top > x and .Top < y and .Left > a and .Left < b Then
.Delete
Exit For
End If
End If
Where x,y, a and b are variables or hard-coded values.
Upvotes: 0