PDA

View Full Version : [SOLVED:] Deleting off-slide content / objects VBA



RayKay
12-14-2018, 03:19 AM
Hi everyone

I'm stuck on how to write VBA so with a click of the button it will delete all objects that are not on the slide - deletes all off-slide content.

I know there's the option in FILE > Check for Issues and then click Off-slide content, but it's long winded to remove all the other radio buttons. Also, that tool isn't available when customizing the ribbon.

Can anyone send me code please? I'm sure others would find this useful too.
(PowerPoint 2016)

Thank you!

John Wilson
12-14-2018, 07:40 AM
This should do thet (check on a copy though)


Sub Zaps_OffSlide()
Dim osld As Slide
Dim oshp As Shape
Dim L As Long
For Each osld In ActivePresentation.Slides
For L = osld.Shapes.Count To 1 Step -1
Set oshp = osld.Shapes(L)
If isOffSlide(oshp) Then oshp.Delete
Next L
Next
End Sub




Function isOffSlide(oshp As Shape) As Boolean
Dim SW As Long
Dim SH As Long
SH = ActivePresentation.PageSetup.SlideHeight
SW = ActivePresentation.PageSetup.SlideWidth
With oshp
If .Left + .Width < 0 _
Or .Top + .Height < 0 _
Or .Top > SH _
Or .Left > SW Then isOffSlide = True
End With
End Function

RayKay
12-14-2018, 07:56 AM
Thank you John! You are a LEGEND. I've been using your site randomly for months now, always seems to be you with 99% of the answers!! THANK YOU !!!