• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Application does not close

Hi all,

I am trying to copy chart/shape from excel to powerpoint and save it as different files based on region. It is working fine, but somehow when I save it as a single file, the powerpoint app close, while in different files it is not. Here is the sample code that does not working
Code:
Set oPS = Nothing
  oPP.PageSetup.SlideSize = ppSlideSizeOnScreen
  oPP.SaveAs ThisWorkbook.Path & "\" & FileName & ".pptx"
  oPP.Close
Next i
oPA.Quit
ActiveWorkbook.Sheets(1).Select
If Not oPS Is Nothing Then Set oPS = Nothing
If Not oPP Is Nothing Then Set oPP = Nothing
If Not oPA Is Nothing Then Set oPA = Nothing

which I modified from this which is working
Code:
Set oPS = Nothing
oPP.SaveAs ThisWorkbook.Path & "\" & NmFile & ".pptx"
oPP.Close
oPA.Quit
ActiveWorkbook.Sheets(1).Select
If Not oPS Is Nothing Then Set oPS = Nothing
If Not oPP Is Nothing Then Set oPP = Nothing
If Not oPA Is Nothing Then Set oPA = Nothing

Any idea why? Thanks in advance
 
Hi ,

What is the meaning of not working ? What actually happens ?

Can you post the complete code ? Within the For ... Next loop , are you modifying the variable FileName ?

Narayan
 
Code:
Option Explicit
Dim sht As Variant
Dim oPA As PowerPoint.Application
Dim oPP As PowerPoint.Presentation
Dim oPS As PowerPoint.Slide
Dim sr As PowerPoint.ShapeRange
Dim oShape As PowerPoint.Shape
Dim NamaProv, NamaKab As String
Dim NmFile, cnt, i, JudulSlide, j, k
Dim AwalKab, AkhirKab
Dim Ch2_Top, Ch2_Left
Dim Jml_Kab, Pengali
Dim AktifProv, NoProv, KdKab
Sub Gabungan()
On Error GoTo ErrHandler
Set oPA = New PowerPoint.Application
oPA.Visible = msoTrue

NoProv = 0
For i = 532 To 499 Step -1
  Set oPP = oPA.Presentations.Add(msoTrue)
  oPA.ActivePresentation.PageSetup.SlideSize = ppSlideSizeA4Paper
  cnt = 0
  AktifProv = ActiveWorkbook.Sheets("ANALY").Range("A" & i).Value
  NmFile = AktifProv
  KdKab = Worksheets("ANALY").Range("C" & i).Value
  Worksheets("ANALY").Range("kab_aktif").Value = KdKab
  NamaProv = ActiveWorkbook.Sheets("ANALY").Range("A" & i).Value
  NamaKab = ActiveWorkbook.Sheets("ANALY").Range("D" & i).Value
  ' copy dan paste province
  If Not (KdKab = 219 Or KdKab = 410 Or KdKab = 439 Or KdKab = 441) Then
  If Range("sas_dau").Value <> 0 Then
  ' I did not use this IF-ENDIF, just as reminder what i was doing before
  If AktifProv <> NamaProv Then
  AktifProv = NamaProv
  NoProv = NoProv + 1
  End If
  KopiPie
  KopiTabel1
  KopiWB
  KopiTabel2
  End If
  End If
' copy and paste district
  AwalKab = Worksheets("ANALY").Range("K6").Value
  AkhirKab = Worksheets("ANALY").Range("K7").Value
   
  For j = AwalKab To AkhirKab
  KdKab = Worksheets("ANALY").Range("C" & j).Value
  Worksheets("ANALY").Range("kab_aktif").Value = KdKab
  NamaProv = ActiveWorkbook.Sheets("ANALY").Range("A" & j).Value
  NamaKab = ActiveWorkbook.Sheets("ANALY").Range("D" & j).Value
  If Not (KdKab = 219 Or KdKab = 410 Or KdKab = 439 Or KdKab = 441) Then
  If Range("sas_dau").Value <> 0 Then
  ' Again just as reminder
  If AktifProv <> NamaProv Then
  AktifProv = NamaProv
  NoProv = NoProv + 1
  End If
  KopiPie
  ' Grafik WB
  KopiTabel1
  KopiWB
  'Kopi tabelnya
  KopiTabel2
  End If
  End If
  Next j
  Set oPS = Nothing
  oPP.PageSetup.SlideSize = ppSlideSizeOnScreen
  oPP.SaveAs ThisWorkbook.Path & "\27 - Jan 14\" & NmFile & ".pptx"
  oPP.Close
Next i
oPA.Quit
ActiveWorkbook.Sheets(1).Select
If Not oPS Is Nothing Then Set oPS = Nothing
If Not oPP Is Nothing Then Set oPP = Nothing
If Not oPA Is Nothing Then Set oPA = Nothing
Exit Sub
ErrHandler:
  MsgBox Err.Description
  'oPA.Quit
  'ActiveWorkbook.Sheets(1).Select
  'If Not oPS Is Nothing Then Set oPS = Nothing
  'If Not oPP Is Nothing Then Set oPP = Nothing
  'If Not oPA Is Nothing Then Set oPA = Nothing
  Exit Sub
End Sub
 
the sub module KopiPie, KopiTabel1,... only add new slide, copy some chart/shape and then return back to main module

What is not working is that, the powerpoint app is not closing whereas in the second code it is closing (i did not see powerpoint still open when the code has finished). I hope i make my self clear.
 
Hi ,

I am not able to troubleshoot the code ; the statement :

oPA.Quit

is supposed to quit from the Powerpoint application. Can you place the cursor at this line in the code , and press F9 to insert a breakpoint ? Then run the entire procedure ; when it comes to the breakpoint , execution will halt. Now press F8 to step through the code , and see whether Powerpoint closes when the statement is passed.

The second code you refer to has the same statement , I think.

Narayan
 
Yes, that is exactly my point. I have tried to use break point on oPA.Quit and press F8, but does not seem to do anything and there isn't any error message as well. When i look at the powerpoint before oPA.Quit, there are no file open. Just an empty powerpoint app.
 
Email sent.

I run it again before I email it, and it is still the same. I give link to both macro so that you can notice the difference.

Thanks
 
Back
Top