Supercharge your PowerPoint productivity with
Supercharge your PPT Productivity with PPTools - Click here to learn more.

Proud member of

PPTools

Image Export converts PowerPoint slides to high-quality images.

PPT2HTML exports HTML even from PowerPoint 2010 and 2013, gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements

Merge Excel data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more

Resize your presentations quickly and without distortion

Language Selector switches the text in your presentation from one language to another

FixLinks prevents broken links when you distribute PowerPoint presentations

Shape Styles brings styles to PowerPoint. Apply complex formatting with a single click.

Do something to every shape slide or file

Here are simple examples of code that illustrate how you can perform some operation on:

Note: since some of these routines call one another, copy and paste them all into a single module.

Sub EveryTextBoxOnSlide()
' Performs some operation on every shape that contains text on every slide
' (doesn't affect charts, tables, etc)

    Dim oSh As Shape
    Dim oSl As Slide

    On Error GoTo ErrorHandler

    For Each oSl In ActivePresentation.Slides
        For Each oSh In oSl.Shapes
            With oSh
                If .HasTextFrame Then
                    If .TextFrame.HasText Then
                        ' If font size is mixed, don't touch the font size
                        If .TextFrame.TextRange.Font.Size > 0 Then
                            .TextFrame.TextRange.Font.Size = .TextFrame.TextRange.Font.Size + 2
                        End If
                    End If
                End If
            End With
        Next    ' shape
    Next    ' slide

NormalExit:
    Exit Sub

ErrorHandler:
    Resume Next

End Sub

Sub EverySlideInPresentation()
' Performs some operation on every slide in the currently active presentation

    Dim oSl As Slide

    For Each oSl In ActivePresentation.Slides
        ' for example, show its name and index number:
        Debug.Print oSl.Name & vbTab & oSl.SlideIndex

        ' or do something with every shape on the slide:
        Call EveryShapeOnSlide(oSl)

    Next oSl

End Sub

Sub EveryPresentationInFolder()
' Performs some operation on every presentation file in a folder

    Dim sFolder As String   ' Full path to folder we'll examine
    Dim sFileSpec As String ' Filespec, e.g. *.PPT
    Dim sFileName As String ' Name of a file in the folder
    Dim oPres As Presentation

    ' Edit this:
    sFolder = "C:\Files\"    ' must end with a \ character
    sFileSpec = "*.PPT"

    ' Get the first filename that matches the spec:
    sFileName = Dir$(sFolder & sFileSpec)

    While sFileName <> ""
        ' do something with the presentation ...
        ' Open it
        Set oPres = Presentations.Open(sFolder & sFileName, msoFalse)
        ' Display the number of slides in it
        Debug.Print oPres.Slides.Count

        ' Or you could do something to every slide in the presentation:
        Call EverySlideInPresentation

        ' close the presentation
        oPres.Close
        ' release the reference
        Set oPres = Nothing

        ' Once done, see if there's another presentation that meets our spec
        ' then around the loop again
        sFileName = Dir()
    Wend

End Sub

Sub EveryShapeOnSlide(oSl as Slide)
' Performs some operation on every shape on a slide

    Dim oSh As Shape
    On Error GoTo ErrorHandler

    For Each oSh In oSl.Shapes
        ' Show the name of the shape:
        Debug.Print oSh.Name

        ' or whatever else you want to do

        ' for example, ungroup/regroup certain types of shapes:
        Select Case oSh.Type
            Case Is = msoEmbeddedOLEObject, msoLinkedOLEObject, msoPicture
                ' Attempting to ungroup a bitmap image causes an error
                ' but no harm is done; we'll ignore it.
                On Error Resume Next
                oSh.Ungroup.Group
                On Error GoTo ErrorHandler
            Case Else
                ' ignore other shape types
        End Select

    Next oSh

NormalExit:
    Exit Sub

ErrorHandler:
    Resume Next

End Sub


Note: In practice, it's better to collect the filenames first (ie, in an array) then process the filenames from the array
See Do something to every file in a folder

See How do I use VBA code in PowerPoint? to learn how to use this example code.


Did this solve your problem? If so, please consider supporting the PPT FAQ with a small PayPal donation.
Page copy protected against web site content infringement by Copyscape Contents © 1995 - 2022 Stephen Rindsberg, Rindsberg Photography, Inc. and members of the MS PowerPoint MVP team. You may link to this page but any form of unauthorized reproduction of this page's contents is expressly forbidden.

Supercharge your PPT Productivity with PPTools

content authoring & site maintenance by
Friday, the automatic faq maker (logo)
Friday - The Automatic FAQ Maker

Do something to every shape slide or file
http://www.pptfaq.com/FAQ00594_Do_something_to_every_shape_slide_or_file.htm
Last update 07 June, 2011
Created: