|
||
---|---|---|
PowerPoint tips, hints and tutorials that will change your presentations for ever! | ||
Jigsaws |
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 |
|
Articles on your favourite sport Free Microsoft PowerPoint Advice, help and tutorials, Template Links |