Hemsat
04-25-2017, 04:51 PM
Hi,
I am trying to create a macro that will compile all presentations. I want to be able to open up a ppt, run the macro and have a prompt for choosing the folder that will contain all the presentations to be combined. I found something that will work if the files are stored in a test folder on the desktop but tried to modify it for prompt with no success. Please help.
Sub Combine()
Dim sFileTyp As String
Dim sFileName As String
Dim oDonor As Presentation
Dim otarget As Presentation
Dim i As Integer
On Error GoTo errhandler
sFileTyp = "*.PPTX"
sFileName = Dir$(Environ("USERPROFILE") & "\Desktop\Test\" & sFileTyp)
Set otarget = ActivePresentation
Do While sFileName <> ""
Set oDonor = Presentations.Open(Environ("USERPROFILE") & "\Desktop\Test\" & sFileName, msoFalse)
For i = 1 To oDonor.Slides.Count
oDonor.Slides(i).Copy
With otarget.Slides.Paste(otarget.Slides.Count + 1)
.Design = oDonor.Slides(i).Design
.ColorScheme = oDonor.Slides(i).ColorScheme
End With
Next i
oDonor.Close
Set oDonor = Nothing
sFileName = Dir()
Loop
MsgBox "DONE!"
NormalExit:
Exit Sub
ErrorHandler:
Call MsgBox("Error:" & vbCrLf & Err.Number & vbCrLf & Err.Description, _
vbOKOnly, "Error inserting files")
Resume NormalExit
Exit Sub
errhandler:
MsgBox "Sorry, there was an error"
End Sub
Thanks,
Hema
I am trying to create a macro that will compile all presentations. I want to be able to open up a ppt, run the macro and have a prompt for choosing the folder that will contain all the presentations to be combined. I found something that will work if the files are stored in a test folder on the desktop but tried to modify it for prompt with no success. Please help.
Sub Combine()
Dim sFileTyp As String
Dim sFileName As String
Dim oDonor As Presentation
Dim otarget As Presentation
Dim i As Integer
On Error GoTo errhandler
sFileTyp = "*.PPTX"
sFileName = Dir$(Environ("USERPROFILE") & "\Desktop\Test\" & sFileTyp)
Set otarget = ActivePresentation
Do While sFileName <> ""
Set oDonor = Presentations.Open(Environ("USERPROFILE") & "\Desktop\Test\" & sFileName, msoFalse)
For i = 1 To oDonor.Slides.Count
oDonor.Slides(i).Copy
With otarget.Slides.Paste(otarget.Slides.Count + 1)
.Design = oDonor.Slides(i).Design
.ColorScheme = oDonor.Slides(i).ColorScheme
End With
Next i
oDonor.Close
Set oDonor = Nothing
sFileName = Dir()
Loop
MsgBox "DONE!"
NormalExit:
Exit Sub
ErrorHandler:
Call MsgBox("Error:" & vbCrLf & Err.Number & vbCrLf & Err.Description, _
vbOKOnly, "Error inserting files")
Resume NormalExit
Exit Sub
errhandler:
MsgBox "Sorry, there was an error"
End Sub
Thanks,
Hema