我的任务是将一张幻灯片复制到多个ppt演示文稿。所有ppts都在同一个文件夹中。我不知道如何开始。到目前为止,我已经用VBA改变了一些简单的东西,如改变字体,标题等。任何人都可以帮助我吗? 提前致谢
答案 0 :(得分:0)
我发现这个VBA代码可以帮助您入门。这将使用循环将所有幻灯片从第一个演示文稿复制到第二个演示文稿。您可以修改代码以复制单个幻灯片,然后通过循环过去进入多个演示文稿。
Sub main()
Dim objPresentation As Presentation
Dim i As Integer
'open the target presentation
Set objPresentation = Presentations.Open("C:\2.pptx")
For i = 1 To objPresentation.Slides.Count
objPresentation.Slides.Item(i).Copy
Presentations.Item(1).Slides.Paste
Next i
objPresentation.Close
End Sub
例如,如果您打开目标PPTX演示文稿并运行以下VBA宏,它将从2.pptx演示文稿文件中复制第一张幻灯片并将其粘贴到当前目标PPTX中。
Sub copySlide()
Dim objPresentation As Presentation
'open the target presentation
'use path with the file if it is in a different location ("c:\2.pptx")
Set objPresentation = Presentations.Open("2.pptx")
'copy slide 1 from 2.pptx presentation
'change the item number in order to target a different slide
objPresentation.Slides.Item(1).Copy
'paste the slide in target
Presentations.Item(1).Slides.Paste
objPresentation.Close
End Sub
答案 1 :(得分:0)
使用InsertSlideFromFile方法,该方法采用以下形式:
.InsertFromFile(FileName, Index, SlideStart, SlideEnd)
实施例。要从test.pptx复制幻灯片3到4并将它们粘贴到当前打开的演示文稿的末尾(ActivePresentation):
' VBA macro to insert slide(s) from file
' Written by Jamie Garroch of http://youpresent.co.uk/
Sub InsertSlides()
With ActivePresentation.Slides
.InsertFromFile "test.pptx", .Count, 3, 4
End With
End Sub
如果所有文件与打开的演示文稿位于同一路径上,您可以从以下开始自动化路径:
Dim myPath as String
MyPath = ActivePresentation.Path
有关InsertSlideFromFile方法的更多信息:
https://msdn.microsoft.com/en-us/library/office/ff746047.aspx?f=255&MSPPError=-2147217396