Programmatically combine slides from multiple presentations into a single presentation

I need to automate the creation of a presentation (OpenOffice or Powerpoint). The presentation should include the first two slides of each of the presentations in this catalog, and then combine them into one presentation. I am confused by what approach I should take to solve this problem. Any pointers would be appreciated.

+7
source share
4 answers

Speaking of PowerPoint, you should use a VBA macro to do the job, something like

Sub Pull() Dim SrcDir As String, SrcFile As String SrcDir = PickDir() If SrcDir = "" Then Exit Sub SrcFile = Dir(SrcDir & "\*.ppt") Do While SrcFile <> "" ImportFromPPT SrcDir + "\" + SrcFile, 1, 2 SrcFile = Dir() Loop End Sub 

When choosing the source directory, you can use this function

 Private Function PickDir() As String Dim FD As FileDialog PickDir = "" Set FD = Application.FileDialog(msoFileDialogFolderPicker) With FD .Title = "Pick a directory to work on" .AllowMultiSelect = False .Show If .SelectedItems.Count <> 0 Then PickDir = .SelectedItems(1) End If End With End Function 

Now - the main thing - to insert slides from another PPT, and save the original format . This is a tricky thing, since the PPT VBA InsertFromFile method makes no sense. Microsoft gave us a good time to deal with this in countless 20-hour debugging sessions :-), and you need to enter a lot of code to get everything right - much more complicated than using a dialogue manually, in particular if your original slide is rejected from the slide of the main source.

If your PPT adheres to its wizards, you can safely omit all code between "→ →"

 Private Sub ImportFromPPT(FileName As String, SlideFrom As Long, SlideTo As Long) Dim SrcPPT As Presentation, SrcSld As Slide, Idx As Long, SldCnt As Long Set SrcPPT = Presentations.Open(FileName, , , msoFalse) SldCnt = SrcPPT.Slides.Count If SlideFrom > SldCnt Then Exit Sub If SlideTo > SldCnt Then SlideTo = SldCnt For Idx = SlideFrom To SlideTo Step 1 Set SrcSld = SrcPPT.Slides(Idx) SrcSld.Copy With ActivePresentation.Slides.Paste .Design = SrcSld.Design .ColorScheme = SrcSld.ColorScheme ' if slide is not following its master (design, color scheme) ' we must collect all bits & pieces from the slide itself ' >>>>>>>>>>>>>>>>>>>> If SrcSld.FollowMasterBackground = False Then .FollowMasterBackground = False .Background.Fill.Visible = SrcSld.Background.Fill.Visible .Background.Fill.ForeColor = SrcSld.Background.Fill.ForeColor .Background.Fill.BackColor = SrcSld.Background.Fill.BackColor ' inspect the FillType object Select Case SrcSld.Background.Fill.Type Case Is = msoFillTextured Select Case SrcSld.Background.Fill.TextureType Case Is = msoTexturePreset .Background.Fill.PresetTextured (SrcSld.Background.Fill.PresetTexture) Case Is = msoTextureUserDefined ' TextureName gives a filename w/o path ' not implemented, see picture handling End Select Case Is = msoFillSolid .Background.Fill.Transparency = 0# .Background.Fill.Solid Case Is = msoFillPicture ' picture cannot be copied directly, need to export and re-import slide image If SrcSld.Shapes.Count > 0 Then SrcSld.Shapes.Range.Visible = False bMasterShapes = SrcSld.DisplayMasterShapes SrcSld.DisplayMasterShapes = False SrcSld.Export SrcPPT.Path & SrcSld.SlideID & ".png", "PNG" .Background.Fill.UserPicture SrcPPT.Path & SrcSld.SlideID & ".png" Kill (SrcPPT.Path & SrcSld.SlideID & ".png") SrcSld.DisplayMasterShapes = bMasterShapes If SrcSld.Shapes.Count > 0 Then SrcSld.Shapes.Range.Visible = True Case Is = msoFillPatterned .Background.Fill.Patterned (SrcSld.Background.Fill.Pattern) Case Is = msoFillGradient ' inspect gradient type Select Case SrcSld.Background.Fill.GradientColorType Case Is = msoGradientTwoColors .Background.Fill.TwoColorGradient SrcSld.Background.Fill.GradientStyle , _ SrcSld.Background.Fill.GradientVariant Case Is = msoGradientPresetColors .Background.Fill.PresetGradient _ SrcSld.Background.Fill.GradientStyle, _ SrcSld.Background.Fill.GradientVariant, _ SrcSld.Background.Fill.PresetGradientType Case Is = msoGradientOneColor .Background.Fill.OneColorGradient _ SrcSld.Background.Fill.GradientStyle, _ SrcSld.Background.Fill.GradientVariant, _ SrcSld.Background.Fill.GradientDegree End Select Case Is = msoFillBackground ' Only shapes - we shouldn't come here End Select End If ' >>>>>>>>>>>>>>>>>>>> End With Next Idx End Sub 

Only read-only or password-protected are not scanned in the code, and they will be corrupted. Also be careful not to run the collector file itself. Otherwise, it should work. I must admit that for a long time I did not look at the code ,-)

+12
source

You can turn on "powerpoint join" on Google to find a useful tool for combining multiple ppts.

0
source

I'm glad that @miked was able to get what you need.

Another method to consider when using .NET is discussed in this post.

0
source

Simple and quick solution:

 I := PPTPresentation.Slides.InsertFromFile(FileName,X,StartSlideNo,EndSlideNo); PPTPresentation.Slides.Item(I).ApplyTheme(FileName); PPTPresentation.Slides.Item(I).ApplyTemplate(FileName); 

Note: the code is written in Delphi / Pascal, but you can easily convert it ...

0
source

All Articles