PDA

View Full Version : Solved: controling powerpoint with excel vba



chungtinhlak
12-17-2008, 04:29 PM
Is it possible to write vba script in excel to open powerpoint presentation to copy and paste slides into another presentation?

Mahahaava
12-17-2008, 05:21 PM
Hi,

this will copy the Slide # 1 from Pres1.ppt to Pres2.ppt in front of existing slide 1 there:

Sub OpenPowerPoint()
On Error Resume Next
Application.VBE.ActiveVBProject.References.AddFromFile _
"c:\Program Files\Microsoft Office\OFFICE11\MSPPT.OLB"
Dim ofApp As PowerPoint.Application
Dim ofApp2 As PowerPoint.Application
Dim ofFile1 As String
Dim ofFile2 As String
Dim ppPresentation As String
ofFile1 = "C:\Temp\" & "Pres1.ppt"
ofFile2 = "C:\Temp\" & "Pres2.ppt"
Set ofApp = CreateObject("PowerPoint.Application")
ofApp.Visible = True
ofApp.Presentations.Open ofFile1
With ofApp
.ActivePresentation.Slides(1).Copy
End With
Set ofApp2 = CreateObject("PowerPoint.Application")
ofApp2.Visible = True
ofApp2.Presentations.Open ofFile2
With ofApp2
.ActivePresentation.Slides.Paste 1
End With
Set ofApp = Nothing
Set ofApp2 = Nothing
On Error GoTo 0
End Sub
Note that the statement: Application.VBE.ActiveVBProject.References.... is not necessary if you alrady have PowerPoint selected in the Project References.

HTH

Petri

chungtinhlak
12-18-2008, 07:28 AM
thanks