PDA

View Full Version : [SOLVED:] How to import mulitple files into one Power Point presentation.



ma997
10-02-2013, 01:43 PM
I'm using the following code to import all my single slide presentations into ONE presentation. (I have about 100 .pptx files in this directory) Since all the files have the same naming convention, is there a way to use a wild card to import ALL the *.pptx files?

I've tried using ".....Overview July 2013 -Draft_*.pptx" and that will not work. Does anyone know how to accomplish this?

Here is what I am using:


Private Sub CommandButton1_Click()
Dim FileName As String
Dim Index, SlideStart, SlideEnd As Long
ActivePresentation.Slides.InsertFromFile "C:\Documents and Settings\amta\Desktop\Unzipped\Overview July 2013 -DRAFT_0001.pptx", ActivePresentation.Slides.Count, 1
ActivePresentation.Slides.InsertFromFile "C:\Documents and Settings\amta\Desktop\Unzipped\Overview July 2013 -DRAFT_0002.pptx", ActivePresentation.Slides.Count, 1
ActivePresentation.Slides.InsertFromFile "C:\Documents and Settings\amta\Desktop\Unzipped\Overview July 2013 -DRAFT_0003.pptx", ActivePresentation.Slides.Count, 1
End Sub

John Wilson
10-03-2013, 12:41 AM
Maybe something like:

Sub getfiles()
Dim fso As Object
Dim objfolder As Object
Dim objfile As Object
Dim opres As Presentation
Dim strFind As String
strpath = "C:\Documents and Settings\amta\Desktop\Unzipped\" 'Path to your folder must end in \
strFind = "*Overview July 2013 -DRAFT*" ' * is wild card"
Set fso = CreateObject("Scripting.FileSystemObject")
Set objfolder = fso.GetFolder(strpath)
For Each objfile In objfolder.Files
If objfile.Name Like strFind Then
ActivePresentation.Slides.InsertFromFile objfile.Name, ActivePresentation.Slides.Count, 1
End If
Next objfile
Set objsub = Nothing
Set objfile = Nothing
Set objfolder = Nothing
Set opres = Nothing
End Sub

Just for the record

Dim Index, SlideStart, SlideEnd As Long
DOES NOT WORK IN VBA Only SlideEnd will be declared as Long the others as Variant

Dim Index As Long, SlideStart As Long, SlideEnd As Long

ma997
10-03-2013, 07:07 AM
Thanks, I updated my code, but it failed here:

ActivePresentation.Slides.InsertFromFile objfile.Name, ActivePresentation.Slides.Count, 1

Error Message said "slides (unknown member failed)". I'm not sure what to do from here.

John Wilson
10-03-2013, 10:24 AM
Try:

Sub getfiles()
Dim fso As Object
Dim objfolder As Object
Dim objfile As Object
Dim opres As Presentation
Dim strPath As String
Dim strFind As String
strPath = "C:\Documents and Settings\amta\Desktop\Unzipped\" 'Path to your folder must end in \
strFind = "*Overview July 2013 -DRAFT*" ' * is wild card"
Set fso = CreateObject("Scripting.FileSystemObject")
Set objfolder = fso.GetFolder(strPath)
For Each objfile In objfolder.Files
If objfile.Name Like strFind Then
ActivePresentation.Slides.InsertFromFile strPath & objfile.Name, ActivePresentation.Slides.Count, 1
End If
Next objfile
Set objfile = Nothing
Set objfolder = Nothing
Set opres = Nothing
End Sub

ma997
10-03-2013, 11:09 AM
Worked like a charm!!! Thank you!!

On a separate note, all the *.ppt files have the same background. However, when I imported the slides, it changed them all to a plain white background. Is there an easy way to add this to the code?

John Wilson
10-03-2013, 11:44 AM
Easiest way is to start with a presentation having the same background set on the master

ma997
10-03-2013, 11:56 AM
Thanks I realized that after I posted the question. All is working as expected! Thanks so much.