Created
September 6, 2018 07:08
-
-
Save bhandarisaurav/f0da2bcc7f64919e672ed1ea99f5c47f to your computer and use it in GitHub Desktop.
Simple VBA Script to merge or combine all the powerpoint files in a folder into a new one! Steps: Open a new presentation file and save it to the folder all the files you want to combine are in (you can move it later) Paste the code into the VBA window Run the InsertAllSlides macro and it will combine them.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub InsertAllSlides() | |
' Insert all slides from all presentations in the same folder as this one | |
' INTO this one; do not attempt to insert THIS file into itself, though. | |
Dim vArray() As String | |
Dim x As Long | |
' Change "*.PPT" to "*.PPTX" or whatever if necessary: | |
EnumerateFiles ActivePresentation.Path & "\", "*.PPTX", vArray | |
With ActivePresentation | |
For x = 1 To UBound(vArray) | |
If Len(vArray(x)) > 0 Then | |
.Slides.InsertFromFile vArray(x), .Slides.Count | |
End If | |
Next | |
End With | |
End Sub | |
Sub EnumerateFiles(ByVal sDirectory As String, _ | |
ByVal sFileSpec As String, _ | |
ByRef vArray As Variant) | |
' collect all files matching the file spec into vArray, an array of strings | |
Dim sTemp As String | |
ReDim vArray(1 To 1) | |
sTemp = Dir$(sDirectory & sFileSpec) | |
Do While Len(sTemp) > 0 | |
' NOT the "mother ship" ... current presentation | |
If sTemp <> ActivePresentation.Name Then | |
ReDim Preserve vArray(1 To UBound(vArray) + 1) | |
vArray(UBound(vArray)) = sDirectory & sTemp | |
End If | |
sTemp = Dir$ | |
Loop | |
End Sub | |
How can I keep source formatting? what do I add to this code to make it work?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello everyone, I'm new to the community but I'm working on joining two PowerPoint presentations but for certain slides using a text file (batch guide), but I haven't been able to get it to work. I'm sharing my code with you in case anyone has any suggestions to make it work, I would really appreciate it. A hug to everyone.
..................
Sub InsertAllSlidesFromBatch()
Dim fso As Object
Dim fileStream As Object
Dim line As String
Dim parts As Variant
Dim filePath As String
Dim slideNumber As Integer
Dim pptMain As Presentation
Dim fd As FileDialog
Dim savePath As String
Cleanup:
' Liberar objetos
On Error Resume Next
If Not fileStream Is Nothing Then fileStream.Close
Set fso = Nothing
Set fileStream = Nothing
Set fd = Nothing
If Not pptMain Is Nothing Then pptMain.Close
Exit Sub
ErrorHandler:
MsgBox "Se produjo un error: " & Err.Description, vbCritical
Resume Cleanup
End Sub
Sub ProcessSlideFromBatch(filePath As String, slideNumber As Integer, pptMain As Presentation)
Dim pptSource As Presentation
SlideError:
MsgBox "Error al procesar la diapositiva del archivo: " & filePath & vbCrLf & Err.Description, vbCritical
If Not pptSource Is Nothing Then pptSource.Close
Set pptSource = Nothing
End Sub
...........................