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.

Batch: Do something to every file in a folder

This is a very simple-minded approach you can use to run quick 'n dirty macros on every presentation in a folder.

Also see Do something to -- every shape on a slide, every slide in a presentation, every presentation in a folder for more example code.

You need to edit the FolderPath and FileSpec lines in ForEachPresentation below before you use this.
Then edit MyMacro do do whatever you need it to do.
MyMacro will be called for each file in FolderPath that matches FileSpec

Sub ForEachPresentation()
' Run a macro of your choosing on each presentation in a folder

    Dim rayFileList() As String
    Dim FolderPath As String
    Dim FileSpec
    Dim strTemp As String
    Dim x As Long

    ' EDIT THESE to suit your situation
    FolderPath = "c:\some\folder\"  ' Note: MUST end in \
    FileSpec = "*.ppt"
    ' END OF EDITS

    ' Fill the array with files that meet the spec above
    ReDim rayFileList(1 To 1) As String
    strTemp = Dir$(FolderPath & FileSpec)
    While strTemp <> ""
        rayFileList(UBound(rayFileList)) = FolderPath & strTemp
        ReDim Preserve rayFileList(1 To UBound(rayFileList) + 1) As String
        strTemp = Dir
    Wend

    ' array has one blank element at end - don't process it
    ' don't do anything if there's less than one element
    If UBound(rayFileList) > 1 Then
        For x = 1 To UBound(rayFileList) - 1
            Call MyMacro(rayFileList(x))
        Next x
    End If

End Sub

Sub MyMacro(strMyFile As String)
' this gets called once for each file that meets the spec you enter in ForEachPresentation
' strMyFile is set to the file name each time

    ' Probably at a minimum, you'd want to:
    Dim oPresentation As Presentation
    Set oPresentation = Presentations.Open(strMyFile)

    With oPresentation

        ' do something

    End With

    oPresentation.Save
    oPresentation.Close

End Sub

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

Search terms:


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

Batch: Do something to every file in a folder
http://www.pptfaq.com/FAQ00536_Batch-_Do_something_to_every_file_in_a_folder.htm
Last update 07 June, 2011
Created: