Running Powerpoint from Excel

  • Thread starter Thread starter Naveen Sukhramani
  • Start date Start date
N

Naveen Sukhramani

I wrote this code to activate a powerpoint file (as a slideshow) and
quit powerpoint after the show is through and return to excel.

The problem: Within secs of opening the file in powerpoint it quits
(without running running the entire slideshow.


Sub myShow()
Dim zPPT As PowerPoint.Application
Dim zPres As PowerPoint.Presentation

Set zPPT = CreateObject("Powerpoint.Application")

zPPT.Visible = msoTrue

Set zPres = zPPT.Presentations.Open("prezex.ppt")
zPres.SlideShowSettings.Run

zPPT.Quit

End Sub

xxxxxxxxxxxxxxxxxxxx

Could someone help?

Thanks,

Naveen
 
Try using module level variables. Put your Dims at the module top outside
of the subs.

--
Jim Rech
Excel MVP
|I wrote this code to activate a powerpoint file (as a slideshow) and
| quit powerpoint after the show is through and return to excel.
|
| The problem: Within secs of opening the file in powerpoint it quits
| (without running running the entire slideshow.
|
|
| Sub myShow()
| Dim zPPT As PowerPoint.Application
| Dim zPres As PowerPoint.Presentation
|
| Set zPPT = CreateObject("Powerpoint.Application")
|
| zPPT.Visible = msoTrue
|
| Set zPres = zPPT.Presentations.Open("prezex.ppt")
| zPres.SlideShowSettings.Run
|
| zPPT.Quit
|
| End Sub
|
| xxxxxxxxxxxxxxxxxxxx
|
| Could someone help?
|
| Thanks,
|
| Naveen
 
Naveen -

I'm not sure the Excel macro waits for the entire slide show to run
before executing the zPPT.Quit command. You could add a class module in
your Excel project to capture the PowerPoint events. I used the
following code, which fires the SlideShowEnd event procedure. Apparently
you cannot quit the app from within the event procedure, so I use OnTime
to run a separate procedure that quits PowerPoint, after the event
procedure is finished.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______

Class module in Excel VBA, named CPptAppEvt
'----------------
Option Explicit

Public WithEvents pApp As PowerPoint.Application

Private Sub pApp_SlideShowEnd(ByVal Pres As PowerPoint.Presentation)
Application.OnTime Now + TimeValue("0:00:01"), "EndShow"
End Sub
'----------------

Regular module in Excel VBA
'----------------
Option Explicit

Dim zPPT As PowerPoint.Application
Dim zApp As New CPptAppEvt

Sub myShow()
Dim zPres As PowerPoint.Presentation

Set zPPT = CreateObject("Powerpoint.Application")

Set zApp.pApp = zPPT
zPPT.Visible = msoTrue

Set zPres = zPPT.Presentations.Open _
("C:\Documents and Settings\Jon Peltier\My Documents\prezex.ppt")
zPres.SlideShowSettings.Run
End Sub

Sub EndShow()
Dim preso As PowerPoint.Presentation
For Each preso In zPPT.Presentations
preso.Close 'False
Next
zPPT.Quit '' this line gives the error
End Sub
'----------------
 
Back
Top