PDA

View Full Version : Quiting PowerPoint from an Excel Macro



paddysheeran
07-29-2013, 01:57 AM
Hi All,

I'm using the following piece of code to open a PowerPoint presentation and save the slides as images for insertion into a word document.


Dim PPT As PowerPoint.Application
Set PPT = New PowerPoint.Application
PPT.Presentations.Open Filename:=ActiveWorkbook.Path & "\Conferencing_Dashboard" & ".pptx"

Dim sImagePath As String
Dim sImageName As String
Dim oSlide As Slide '* Slide Object
On Error GoTo Err_ImageSave

'sImagePath = ActivePresentation.Path

Filename = 1

For Each oSlide In PPT.ActivePresentation.Slides
sImageName = oSlide.Name & ".jpg"
oSlide.Export ActiveWorkbook.Path & "\" & Filename, "JPG"
Filename = Filename + 1
Next oSlide

Err_ImageSave:
If Err <> 0 Then
MsgBox Err.Description
End If
PPT.Activate
PPT.Quit
Set PPT = Nothing

The code works fine but PPT.Quit does not close down PowerPoint. Can anyone help?

thanks,

Paddy.

John Wilson
07-29-2013, 09:29 AM
It quits here but I don't get jpgs (because the filename doesn't include ".jpg"

I would close the opened presentation before quitting too.

Dim PPT As PowerPoint.Application
Dim filename As Long
Dim opres As Presentation

Dim sImagePath As String
Dim sImageName As String
Dim oSlide As Slide '* Slide Object
On Error GoTo Err_ImageSave

'sImagePath = ActivePresentation.Path
Set PPT = New PowerPoint.Application
Set opres = PPT.Presentations.Open(filename:="C:\Users\John\Desktop\pendula.pptx")
filename = 1

For Each oSlide In PPT.ActivePresentation.Slides
sImageName = oSlide.Name & ".jpg"
oSlide.Export ActiveWorkbook.Path & "\" & filename & ".jpg", "JPG"
filename = filename + 1
Next oSlide

Err_ImageSave:
If Err <> 0 Then
MsgBox Err.Description
End If
opres.Close
PPT.Quit
Set PPT = Nothing

paddysheeran
07-30-2013, 01:53 AM
opres.close does close the presentation but PPT.Quit still does not close down powerpoint.

John Wilson
07-30-2013, 06:16 AM
Try PPT.CommandBars.ExecuteMso("FileExit") instead of PPT.Quit see if that works

paddysheeran
07-30-2013, 06:29 AM
Try PPT.CommandBars.ExecuteMso("FileExit") instead of PPT.Quit see if that works

found this on another forum which has done the trick!


Sub ForcePowerpointExit()

Dim BruteForce As String
BruteForce = "TASKKILL /F /IM powerpnt.exe"
Shell BruteForce, vbHide
End Sub