PowerPoint automation, process won't end after Quit()

T

Thomas Tutko

I'm trying to do some Powerpoint automation from an ASP.NET page and
generate/modify a slide. That piece of the code works fine but when it's all
done running and even after I call the Quit() method on the powerpoint
application object, POWERPOINT.EXE remains running and eventually this is
causing problems. I've googled this extensively and nothing I've found has
seemed to help. I really need this to work properly.

Here's my relevant code. I don't believe i'm using any Global references and
I've even removed the COM reference from my website to use Late Binding
instead in hopes that it would solve my problems as mentioned in this MSDN
Article: http://support.microsoft.com/default.aspx?scid=kb;en-us;319832

Code:
Public Function GenerateDrillDown(ByVal strFileName As String) As Boolean
Dim App As Object = Nothing
Dim pres As Object = Nothing
Dim slide As Object = Nothing

Try
App = CreateObject("PowerPoint.Application")
App.Visible = -1 ' For debugging. Comment this out or set to 0 to keep
the application from being visible.

pres = App.Presentations.Open("C:\DevProjects\Docs\DrillDown.ppt", 0,
-1, -1)
slide = pres.Slides(1) ' There's only one slide in this ppt i'm using as
the template.

slide.Shapes.Item("Text Box 8").TextFrame.TextRange.Text = DecisionTitle
' These are all string variables
slide.Shapes.Item("Text Box 13").TextFrame.TextRange.Text = Narrative
slide.Shapes.Item("Text Box 14").TextFrame.TextRange.Text = Issues
slide.Shapes.Item("Text Box 19").TextFrame.TextRange.Text = Scope

If TopicType = 1 Then
slide.Shapes.Item("Autoshape 9").TextFrame.TextRange.Text =
IDNumber.ToString()
slide.Shapes.Item("Autoshape 9").Visible = -1
slide.Shapes.Item("Autoshape 56").Visible = 0
ElseIf TopicType = 2 Then
slide.Shapes.Item("Autoshape 56").TextFrame.TextRange.Text = "ST" &
IDNumber.ToString()
slide.Shapes.Item("Autoshape 56").Visible = -1
slide.Shapes.Item("Autoshape 9").Visible = 0
End If

pres.SaveAs(strFilename, 1, 0)
Catch ex As Exception
Return False
Finally
' Most of this is coming from another article I found online to help
combat the problem of open references with office automation.
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect() ' Intentionally repeated
GC.WaitForPendingFinalizers()
If Not slide Is Nothing Then
Marshal.FinalReleaseComObject(slide)
slide = Nothing
End If

If Not pres Is Nothing Then
pres.Close()
Masrhal.FinalReleaseComObject(pres)
pres = Nothing
End If

If Not App Is Nothing Then
App.Quit() ' This doesn't do anything, no errors but ap stays open
Marshal.FInalReleaseComObject(App)
App = Nothing
End If
End Try

Return True
End Function

Please give me some guidance as this is an important piece of functionality
required by my project. Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top