2016-06-17 65 views
0

我有任務將一張幻燈片複製到多個PPT演示文稿。所有的PPT都在同一個文件夾中。我不知道如何開始。到目前爲止,我已經用VBA改變了一些簡單的東西,比如改變字體,標題等。任何人都可以幫助我? 在此先感謝將一張幻燈片複製到多個演示文稿

回答

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 
0

使用InsertSlideFromFile方法,該方法採用這種形式:

.InsertFromFile(FileName, Index, SlideStart, SlideEnd) 

實施例。至3個test.pptx複製幻燈片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

相關問題