Merging Powerpoint Files

Hi @Kuki_Force
Try this Vb.net code to merge two powerpoint file.

’ Declare variables for the PowerPoint application and the source and destination files
Dim pptApp As PowerPoint.Application
Dim srcFile1 As String
Dim srcFile2 As String
Dim destFile As String

’ Set the file paths for the source and destination files
srcFile1 = “C:\Users\User\Desktop\File1.pptx”
srcFile2 = “C:\Users\User\Desktop\File2.pptx”
destFile = “C:\Users\User\Desktop\MergedFile.pptx”

’ Create an instance of the PowerPoint application
Set pptApp = New PowerPoint.Application

’ Open the destination file
Dim destPres As PowerPoint.Presentation
Set destPres = pptApp.Presentations.Open(destFile)

’ Open the first source file
Dim srcPres1 As PowerPoint.Presentation
Set srcPres1 = pptApp.Presentations.Open(srcFile1)

’ Insert the slides from the first source file into the destination file
For Each slide In srcPres1.Slides
destPres.Slides.InsertFromFile(srcFile1, slide.SlideIndex, 1, 1)
Next

’ Close the first source file
srcPres1.Close

’ Open the second source file
Dim srcPres2 As PowerPoint.Presentation
Set srcPres2 = pptApp.Presentations.Open(srcFile2)

’ Insert the slides from the second source file into the destination file
For Each slide In srcPres2.Slides
destPres.Slides.InsertFromFile(srcFile2, slide.SlideIndex, 1, 1)
Next

’ Close the second source file
srcPres2.Close

’ Save and close the destination file
destPres.Save
destPres.Close

’ Quit the PowerPoint application
pptApp.Quit

’ Release the object variables
Set destPres = Nothing
Set srcPres2 = Nothing
Set srcPres1 = Nothing
Set pptApp = Nothing

Hope it will works

1 Like