Instructor PPTX VBA - Removing out of slide boundary Color Selector Shape

How to manipulate shapes out of borders of your PPTX Slides

If your like me, you find the out of bounds unnecessary shapes in your PPTX distracting when working with pptx files.



here is a script that will:
  • detect how many slide masters you have in a pptx
  • then loop through each layout in each slide master
  • it then detects all shapes, determines if they are groups
  • if the group is out of bounds and is the exact size of the color selector group:
    • it shows you the group for final validation and asks you if you want to delete it

Option Explicit

Sub ColorGroupCheck()
    Dim shp As Shape
    Dim sld As Slide
    Dim oMaster As Design
    Dim oLayout As CustomLayout
    Dim sldHeight As Long
    Dim userResponse As Integer
    'Debug.Print ActivePresentation.PageSetup.SlideHeight
    'Debug.Print ActivePresentation.Designs.Count
    sldHeight = ActivePresentation.SlideMaster.Height
    
    For Each oMaster In ActivePresentation.Designs
        'Debug.Print oMaster.SlideMaster.CustomLayouts.Count
        ActiveWindow.ViewType = ppViewMasterThumbnails
        
        For Each shp In oMaster.SlideMaster.Shapes
            shp.Select
            CheckFor_ColorGroup shp
        Next shp
        
        For Each oLayout In ActivePresentation.SlideMaster.CustomLayouts
            ActiveWindow.ViewType = ppViewMasterThumbnails
                oLayout.Select
                For Each shp In oLayout.Shapes
                    shp.Select
                    CheckFor_ColorGroup shp
                Next shp
        Next oLayout
    Next oMaster

End Sub

Sub CheckFor_ColorGroup(myShp)
    Dim myUserResponse As Integer
    Select Case myShp.Type
        Case msoGroup
            If myShp.Top < -5 And myShp.Width > 235 And myShp.Width < 236 Then
                myUserResponse = MsgBox("grp outside top = " & myShp.Top, vbYesNo, "Review selected Group, do you want to delete it?")
            End If
        
            Select Case myUserResponse
            Case 6
                ' yes button
                myShp.Delete
            Case 7
                ' no button, do nothing
            End Select
    End Select
End Sub

See a more detailed blob about this script

I am not a VBA expert, so if you have better ways to do this, please comment and I may update this example with better coding practices.

I used the following sources as references:

Comments

Popular posts from this blog

Advanced Network Security Troubleshooting and Solutions v22.411 (ANSTS)

Arubanetworks Webgate - Copy and Paste instructions