Hi Sanjeev,
Let's try this code. Obviously, you need to make sure PowerPoint is configured to allow Macros to run. You will need to update the file paths for
'FileA.pptx', 'FileB.pptx', and
'MergedFile.pptx' to match the actual file paths on your computer.
The code provided takes two PowerPoint files, each containing 100+ slides, and merges them together in an alternating fashion with the slide names reflecting the alternating pattern (A1, B1, A2, B2, A3, B3, etc.).
The code opens the first PowerPoint file (File A) and the second PowerPoint file (File B). It then inserts slides from File B into File A in an alternating fashion, and adds a prefix to the slide names to reflect the alternating pattern.
For example, the first slide from File A will be renamed to "A1", the first slide from File B will be renamed to "B2", the second slide from File A will be renamed to "A3", the second slide from File B will be renamed to "B4", and so on.
The code then saves the merged PowerPoint file as a new file called "MergedFile.pptx" and closes both files. Finally, it cleans up any objects used in the code.
Note that the notes added to the slides indicate which file the original slide came from and what its original slide number was, but the slide names themselves are renamed with the prefix reflecting the alternating pattern.
Let me know if you get any errors.
Good luck!
Chris
VBA Code:
Sub MergePPTX()
Dim PPT1 As Presentation
Dim PPT2 As Presentation
Dim SlideA As Slide
Dim SlideB As Slide
Dim i As Integer
'Open the first PowerPoint file
Set PPT1 = Presentations.Open("C:\Path\To\FileA.pptx")
'Open the second PowerPoint file
Set PPT2 = Presentations.Open("C:\Path\To\FileB.pptx")
'Insert slides from the second file into the first file in alternating fashion
For i = 1 To PPT2.Slides.Count
Set SlideB = PPT2.Slides(i)
Set SlideA = PPT1.Slides.Add(PPT1.Slides.Count + 1, SlideB.Layout)
SlideB.Copy
SlideA.Shapes.Paste
Set SlideB = Nothing
Set SlideA = Nothing
Set SlideA = PPT1.Slides(PPT1.Slides.Count)
SlideA.Name = "A" & CStr((i * 2) - 1)
SlideA.NotesPage.Shapes.Placeholders.Item(2).TextFrame.TextRange.Text = "Slide " & PPT1.Slides.Count & " from File A"
If i < PPT2.Slides.Count Then
Set SlideA = PPT1.Slides.Add(PPT1.Slides.Count + 1, PpSlideLayout.ppLayoutTitleOnly)
SlideA.Name = "B" & CStr(i * 2)
SlideA.NotesPage.Shapes.Placeholders.Item(2).TextFrame.TextRange.Text = "Slide " & PPT1.Slides.Count & " from File B"
Set SlideB = PPT2.Slides(i + 1)
SlideB.Copy
SlideA.Shapes.Paste
Set SlideB = Nothing
Set SlideA = Nothing
End If
Next i
'Save the merged PowerPoint file
PPT1.SaveAs "C:\Path\To\MergedFile.pptx"