Consulting

Results 1 to 3 of 3

Thread: Deleting off-slide content / objects VBA

  1. #1
    VBAX Contributor
    Joined
    Dec 2018
    Location
    South London
    Posts
    115
    Location

    Deleting off-slide content / objects VBA

    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!

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    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
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Contributor
    Joined
    Dec 2018
    Location
    South London
    Posts
    115
    Location
    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 !!!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •