Header
PowerPoint tips, hints and tutorials that will change your presentations for ever!

INDEX

 

Jigsaws
Sounds
Video
Custom Shows
vba code
NaviSlides
Games for teachers
Bullets
Triggers
Security
Flash Cards
Multiple Instances
PowerPoint 2007
Mail Merge
Random events
Animation
Hyperlinks
Set spellcheck language


Home buttonTutorial buttonContact buttonProducts button


Open All PowerPoint Files in a Folder and Sub Folders and Modify

This code uses the File Scripting object 's powerful file handling methods to open all files that meet the specification (in this case .ppt. .pptx. .pptm) inclding any in sub folders. You need to add code to make any modification where indicated. Change the file specification and the path to the folder in strpath and strsuffix.

Sub getfiles() 
    Dim fso As Object 
    Dim objfolder As Object 
    Dim objfile As Object 
    Dim opres As Presentation 
    Dim strSuffix As String 
    Dim strpath As String 
    Dim objsub As Object 
    strpath = "C:\Test\" 'Path to your folder must end in \
    strSuffix = "*.ppt*" 'File suffix note * is wild card
    Set fso = CreateObject("Scripting.FileSystemObject") 
    Set objfolder = fso.GetFolder(strpath) 
     ' main folder
    For Each objfile In objfolder.Files 
        If objfile.Name Like strSuffix Then 
            Set opres = Presentations.Open(objfile.Path, msoFalse) 
             'do whatever here (delete example below)
            MsgBox "Name of file = " & objfile.Name & vbCrLf & "It has " & opres.Slides.Count & " Slides." 
            opres.Close 
        End If 
    Next objfile 
     ' Sub Folders
    For Each objsub In objfolder.SubFolders 
        For Each objfile In objsub.Files 
            Debug.Print objfile.Name 
            If objfile.Name Like strSuffix Then 
                Set opres = Presentations.Open(objfile.Path, msoFalse) 
                 'do whatever here (delete example below)
                MsgBox "Name of file = " & objfile.Name & vbCrLf & "It has " & opres.Slides.Count & " Slides." 
                opres.Close 
            End If 
        Next objfile 
    Next objsub 
     
    Set objsub = Nothing 
    Set objfile = Nothing 
    Set objfolder = Nothing 
    Set opres = Nothing 
End Sub 

Can't use code

 

 

Back to the Index Page

POWERPOINT BLOG

Articles on your favourite sport

Free Microsoft PowerPoint Advice, help and tutorials, Template Links
This website is sponsored by Technology Trish Ltd
© Technology Trish 2007
Registered in England and Wales No.5780175
PowerPoint® is a registered trademark of the Microsoft Corporation