问题
I have task to copy one slide to multiple ppt presentations. All ppts are in same folder. I don't have an idea how to start. So far I have change some simple stuff with VBA as changing font, title etc. Anybody can help me? Thanks in advance
回答1:
I found this VBA code that may help you get started. This will copy all of the slides from the first presentation to a second presentation using a loop. You can modify the code to copy a single slide and then past into multiple presentations with the loop.
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
For example, if you open the target PPTX presentation and run the following VBA macro, it will copy the first slide out of the 2.pptx presentation file and paste it into the current target 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
回答2:
Use the InsertSlideFromFile method which takes this form:
.InsertFromFile(FileName, Index, SlideStart, SlideEnd)
Example. To copy slides 3 to 4 from test.pptx and paste them to the end of your currently open presentation (the 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
If all files are on the same path as the open presentation, you can automate the path by starting with this:
Dim myPath as String
MyPath = ActivePresentation.Path
More info on the InsertSlideFromFile method here:
https://msdn.microsoft.com/en-us/library/office/ff746047.aspx?f=255&MSPPError=-2147217396
来源:https://stackoverflow.com/questions/37891687/copy-one-slide-to-multiple-presentation