微软的三大件用得太多了,并且是真的香。譬如,在汇报工作时,就会使用Powerpoint(以下用PPT代称)。但是由于每个人所使用的模板与样式是不同的,而在报告的时候,有时又需要把这些文件合并到一个PPT里,这可真是一个麻烦事儿。
Powerpoint (PPT) has been greatly used in daily presentation and report, and there are chances that you might merge severl PPTs with different design and themes into one. What is really a boring and tiring thing.
复制/粘贴,当然这是一个很蠢的方法,不过是一个解决之法,放出来供大家参考。The instinctive and stupid way to solve this is just Coping?and?Pasting
.
Ctrl+N
新建一个PPT,用B指代;全选Ctrl+A
,复制Ctrl+C
,然后切换到B里,移到到最后,鼠标点击一下,然后粘贴Ctrl+V
, 此时,将会出现一个选项,在下面选择保持源格式/Keep?Source?Formatting
即可。Ctrl+N
to create a new PPT, referred as B.Select All/Ctrl+A
, Copy/Ctrl+C
in source PPT, and then switch to destination PPT B, select where you want to insert the slides at the left most panel, press Paste/Ctrl+V
, an option panel will show up, and you should select Keep?Source?Formatting
to preserve the source format.PowerPoint提供了一个方法:重用PPT,你可以在「主页→幻灯片→新建幻灯片→重用幻灯片」(「Home→Slides→New Slides→Reuse SLides」)里找到。这样就可以在右侧出现一个面板,用来选择对应的文件,然后插入幻灯片。注意,需要在插入之前勾选最下方的「保留源格式/Keep Source Formatting」。
PowerPoint provide a method named Reuse Slids, and therefore you can ulitize this function to imports slides following the hyperlink given before. Be caution, you should check [Keep Source Formatting] before you reuse any slides in order to preserve the format.
说实话,上面的方案都不好用,为什么呢?因为一旦文件多起来,你就只有浪费一上午在这上面了。所以还需要其它方法。
VBA当然会是一个好的方法,但是呢,Powerpoint里的VBA不像Excel里那么方便,并没有提供录制宏的功能,所以一切都需要自力更生,去网上找代码,找参考。
最终,从网上的内容里拼凑出了如下的代码。最关键的内容可以在代码里找到出处。当然,还找到了非常多的其它内容,但是要么不好用,要么已经在这个内容里包含了,所以就未一一地给出链接了。
使用方法:
Alt+F11
,打开宏编辑器,在「Project」面板,「Insert→Module」,并打开该Module;MergeAllPptFromSelectFolder
这个Sub里,F5
运行。MergeAllPptFromSelectFolder
这个Sub。Actually, Solution 1 and 2 is time-cosuming, boring and tiring, for that you shall spend a whole morning acting repeatly.
VBA(VBScript for Application) is designed to handle such situation. However, VBA in Powerpoint isn‘t as convenient as that in Excel, since no Record Macro is provided. We have to spend days and nights for seeking codes and reference.
Fortunately, I worked out and the code is combined as follows. The critical reference is given in the code, and many others are ignored, unnecessary or repeating.
Usage:
Alt+F11
to open the marco editor, in [Project] panel, [Insert→Module], and open the module;MergeAllPptFromSelectFolder
and the press F5
,F5
and the select MergeAllPptFromSelectFolder
to run it.Save?as
.‘ FROM https://stackoverflow.com/questions/5316459/programmatically-combine-slides-from-multiple-presentations-into-a-single-presen
‘ Copyright ?1999-2018 Shyam Pillai, All Rights Reserved.
‘ You are free to use this code within your own applications, add-ins,
‘ documents etc but you are expressly forbidden from selling or
‘ otherwise distributing this source code without prior consent.
‘ This includes both posting free demo projects made from this
‘ code as well as reproducing the code in text or html format.
Option Explicit
Sub MergeAllPptFromSelectFolder()
‘ ScreenUpdating(FindWindowHandle(Application)) = False
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
‘ ScreenUpdating(FindWindowHandle(Application)) = True ‘or False
End Sub
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
Private Sub ImportFromPPT(FileName As String, SlideFrom As Long, SlideTo As Long)
Dim SrcPPT As Presentation, srcSlide As Slide, Idx As Long, SldCnt As Long
Dim i As Long
Dim bMasterShapes As Boolean
ActivePresentation.Slides.InsertFromFile FileName, 0
Set SrcPPT = Presentations.Open(FileName, , , msoFalse)
SldCnt = SrcPPT.Slides.Count
i = 1
For Each srcSlide In SrcPPT.Slides
Debug.Print "i = " & i
‘ Copy from: https://stackoverflow.com/questions/5316459/programmatically-combine-slides-from-multiple-presentations-into-a-single-presen
ActivePresentation.Slides(i).Design = srcSlide.Design
ActivePresentation.Slides(i).ColorScheme = srcSlide.ColorScheme
i = i + 1
Next
SrcPPT.Close
End Sub
方法三已经可以用了,但是了,我不想每次合并的时候都去新建一个PPT,然后复制,粘贴,运行,很麻烦,不是吗?所以又在上面的基础上进行了修改。
Merge_All_PPT.vbs
;__Batch__Merged__.pptx
文件,确认过眼神,就是它了。Solution 3 works well despite that you do: open powerpoint, create a new PPT, open macro editor, copy, paste and run. How boring it is! Isn‘t it? So small modifications are done.
Merge_All_PPT.vbs
;__Batch__Merged__.pptx
in the parent folder.‘ The original of version of merge PowerPoint comes from:
‘ https://www.tek-tips.com/viewthread.cfm?qid=1687770
‘ And some features are added:
‘ 1. Apply to current folder
‘ 2. Copy Design and ColorScheme from original slides
‘ --------------------------------------------------
‘ Version 2
‘ --------------------------------------------------
Dim Application
Const PPTMERGE_FILE = "__Batch__Merged__.pptx"
PPTMERGE_FOLDER = WScript.CreateObject("wscript.shell").CurrentDirectory
Set Application = CreateObject("PowerPoint.Application")
Application.Visible = True
Dim first
first = True
Set fs=CreateObject("Scripting.FileSystemObject")
Dim folder
Set folder = fs.GetFolder(PPTMERGE_FOLDER)
Dim out
Dim ff
For Each ff in folder.Files
If LCase(Right(ff.Path,3))="ppt" OR LCase(Right(ff.Path,4))="pptx" Then
f = PPTMERGE_FOLDER + "\" + ff.Name
If first Then
Dim p
Set out = Application.Presentations.Open(ff)
out.SaveAs PPTMERGE_FOLDER + "\..\" + PPTMERGE_FILE
first = False
Else
out.Slides.InsertFromFile ff, 0
Set SrcPPT = Application.Presentations.Open(ff.Path, , , msoFalse)
SldCnt = SrcPPT.Slides.Count
i = 1
For Each srcSlide In SrcPPT.Slides
Application.ActivePresentation.Slides(i).Design = srcSlide.Design
Application.ActivePresentation.Slides(i).ColorScheme = srcSlide.ColorScheme
i = i + 1
Next
SrcPPT.Close
End If
End If
Next
If Not first Then
out.Save
‘ out.SlideShowSettings.Run
End If
Application.Quit
Set folder = Nothing
Set out = Nothing
Set folder = Nothing
Set Application = Nothing
MsgBox "Merge Done!"
测试环境/Test on:
合并PPT_Powerpint文件_保持主题颜色/Merge PowerPoint Keep Source Format
原文:https://www.cnblogs.com/troy-daniel/p/MergePPT.html