A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Powerpoint, Publisher and Visio » Powerpoint
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

vb.net dll won't release powerpoint



 
 
Thread Tools Display Modes
  #1  
Old December 7th, 2004, 08:56 PM
C Williams
external usenet poster
 
Posts: n/a
Default vb.net dll won't release powerpoint

Hi,

I am writing some VB.NET code that compiles to a dll. There is some
code within it that manipulates Powerpoint 2003.

The dll I am writing is for smart tags, and I am having trouble because
sometimes Powerpoint is remaining running (powerpnt.exe in Task
Manager). One action of my smart tags calls InsertChart (code below).
The designated line causes powerpoint to remain running even after the
user has manually closed the program--when that line is commented out,
powerpoint exits successfully.

Some quick testing I have done indicates that when my code changes the
active presentation (and would require a save), powerpoint doesn't exit.
If I don't actually change the presentation, it exits fine. (I
replaced the troublesome line below with one that changed the text of a
text box and had the same problem.)

If anyone has some insight into what's going on and how I need to
properly release my references to Powerpoint, I would be most
appreciative!

Thanks!

-Casey

'target is of type Powerpoint.TextRange
Public Sub InsertChart(ByVal target As Object, ByVal imagePath As
String) Implements IOfficeInteract.InsertChart
Dim pptApp As PowerPoint.Application
Dim rng As PowerPoint.TextRange
Dim shp As PowerPoint.Shape

Try
'try to grab powerpoint from target
rng = DirectCast(target, PowerPoint.TextRange)
pptApp = rng.Application


*****THE FOLLOWING LINE CAUSES THE PROBLEM. WHEN IT ISN'T COMMENTED,
POWERPOINT REMAINS RUNNING, WHEN IT IS COMMENTED, POWERPOINT CLOSES
SUCCESSFULLY ********
'shp =
pptApp.ActiveWindow.Selection.SlideRange.Shapes.Ad dPicture(imagePath, _
' Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoTrue, _
' 0, 0, 100, 100)

**********************

Catch ex As Exception
MsgBox("PPT:Error inserting chart:" & ex.Message)
End Try

'clean up is important so that references aren't left in memory
Try
If Not pptApp Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(pptApp)
End If
If Not rng Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(rng)
End If
If Not shp Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(shp)
End If
If Not target Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(target)
End If

Catch ex As Exception
'just eat it at this point
MsgBox("PPT Clean UP ERror: " & ex.Message)
End Try
End Sub
  #2  
Old December 7th, 2004, 10:45 PM
Ben Solomon
external usenet poster
 
Posts: n/a
Default

This doesn't solve your problem but you might consider a hack.

Save the modified PPT under temp name. Delete the modifed PPT. Then Release
the refs as currently done to make it close.


"C Williams" wrote:

Hi,

I am writing some VB.NET code that compiles to a dll. There is some
code within it that manipulates Powerpoint 2003.

The dll I am writing is for smart tags, and I am having trouble because
sometimes Powerpoint is remaining running (powerpnt.exe in Task
Manager). One action of my smart tags calls InsertChart (code below).
The designated line causes powerpoint to remain running even after the
user has manually closed the program--when that line is commented out,
powerpoint exits successfully.

Some quick testing I have done indicates that when my code changes the
active presentation (and would require a save), powerpoint doesn't exit.
If I don't actually change the presentation, it exits fine. (I
replaced the troublesome line below with one that changed the text of a
text box and had the same problem.)

If anyone has some insight into what's going on and how I need to
properly release my references to Powerpoint, I would be most
appreciative!

Thanks!

-Casey

'target is of type Powerpoint.TextRange
Public Sub InsertChart(ByVal target As Object, ByVal imagePath As
String) Implements IOfficeInteract.InsertChart
Dim pptApp As PowerPoint.Application
Dim rng As PowerPoint.TextRange
Dim shp As PowerPoint.Shape

Try
'try to grab powerpoint from target
rng = DirectCast(target, PowerPoint.TextRange)
pptApp = rng.Application


*****THE FOLLOWING LINE CAUSES THE PROBLEM. WHEN IT ISN'T COMMENTED,
POWERPOINT REMAINS RUNNING, WHEN IT IS COMMENTED, POWERPOINT CLOSES
SUCCESSFULLY ********
'shp =
pptApp.ActiveWindow.Selection.SlideRange.Shapes.Ad dPicture(imagePath, _
' Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoTrue, _
' 0, 0, 100, 100)

**********************

Catch ex As Exception
MsgBox("PPT:Error inserting chart:" & ex.Message)
End Try

'clean up is important so that references aren't left in memory
Try
If Not pptApp Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(pptApp)
End If
If Not rng Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(rng)
End If
If Not shp Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(shp)
End If
If Not target Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(target)
End If

Catch ex As Exception
'just eat it at this point
MsgBox("PPT Clean UP ERror: " & ex.Message)
End Try
End Sub

  #3  
Old December 8th, 2004, 03:55 AM
Ken Tucker [MVP]
external usenet poster
 
Posts: n/a
Default

Hi,

Add GC.Collect after you release the com objects.

Ken
----------------


"C Williams" wrote in message
news:RNotd.5342$Wy.250@trndny06...
Hi,

I am writing some VB.NET code that compiles to a dll. There is some
code within it that manipulates Powerpoint 2003.

The dll I am writing is for smart tags, and I am having trouble because
sometimes Powerpoint is remaining running (powerpnt.exe in Task
Manager). One action of my smart tags calls InsertChart (code below).
The designated line causes powerpoint to remain running even after the
user has manually closed the program--when that line is commented out,
powerpoint exits successfully.

Some quick testing I have done indicates that when my code changes the
active presentation (and would require a save), powerpoint doesn't exit.
If I don't actually change the presentation, it exits fine. (I
replaced the troublesome line below with one that changed the text of a
text box and had the same problem.)

If anyone has some insight into what's going on and how I need to
properly release my references to Powerpoint, I would be most
appreciative!

Thanks!

-Casey

'target is of type Powerpoint.TextRange
Public Sub InsertChart(ByVal target As Object, ByVal imagePath As
String) Implements IOfficeInteract.InsertChart
Dim pptApp As PowerPoint.Application
Dim rng As PowerPoint.TextRange
Dim shp As PowerPoint.Shape

Try
'try to grab powerpoint from target
rng = DirectCast(target, PowerPoint.TextRange)
pptApp = rng.Application


*****THE FOLLOWING LINE CAUSES THE PROBLEM. WHEN IT ISN'T COMMENTED,
POWERPOINT REMAINS RUNNING, WHEN IT IS COMMENTED, POWERPOINT CLOSES
SUCCESSFULLY ********
'shp =
pptApp.ActiveWindow.Selection.SlideRange.Shapes.Ad dPicture(imagePath, _
' Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoTrue, _
' 0, 0, 100, 100)

**********************

Catch ex As Exception
MsgBox("PPT:Error inserting chart:" & ex.Message)
End Try

'clean up is important so that references aren't left in memory
Try
If Not pptApp Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(pptApp)
End If
If Not rng Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(rng)
End If
If Not shp Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(shp)
End If
If Not target Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(target)
End If

Catch ex As Exception
'just eat it at this point
MsgBox("PPT Clean UP ERror: " & ex.Message)
End Try
End Sub


  #4  
Old December 8th, 2004, 02:13 PM
Ron Allen
external usenet poster
 
Posts: n/a
Default

Casey,
Have you tried calling Close and Exit/Quit on your pptApp? I believe
you need to do this before releasing the reference to them. I don't have
the reference up just now so I don't remember whether the call is Exit or
Quit.

Ron Allen


"C Williams" wrote in message
news:RNotd.5342$Wy.250@trndny06...
Hi,

I am writing some VB.NET code that compiles to a dll. There is some code
within it that manipulates Powerpoint 2003.

The dll I am writing is for smart tags, and I am having trouble because
sometimes Powerpoint is remaining running (powerpnt.exe in Task Manager).
One action of my smart tags calls InsertChart (code below). The designated
line causes powerpoint to remain running even after the user has manually
closed the program--when that line is commented out, powerpoint exits
successfully.

Some quick testing I have done indicates that when my code changes the
active presentation (and would require a save), powerpoint doesn't exit.
If I don't actually change the presentation, it exits fine. (I replaced
the troublesome line below with one that changed the text of a text box
and had the same problem.)

If anyone has some insight into what's going on and how I need to properly
release my references to Powerpoint, I would be most appreciative!

Thanks!

-Casey

'target is of type Powerpoint.TextRange
Public Sub InsertChart(ByVal target As Object, ByVal imagePath As
String) Implements IOfficeInteract.InsertChart
Dim pptApp As PowerPoint.Application
Dim rng As PowerPoint.TextRange
Dim shp As PowerPoint.Shape

Try
'try to grab powerpoint from target
rng = DirectCast(target, PowerPoint.TextRange)
pptApp = rng.Application


*****THE FOLLOWING LINE CAUSES THE PROBLEM. WHEN IT ISN'T COMMENTED,
POWERPOINT REMAINS RUNNING, WHEN IT IS COMMENTED, POWERPOINT CLOSES
SUCCESSFULLY ********
'shp =
pptApp.ActiveWindow.Selection.SlideRange.Shapes.Ad dPicture(imagePath, _
' Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoTrue, _
' 0, 0, 100, 100)

**********************

Catch ex As Exception
MsgBox("PPT:Error inserting chart:" & ex.Message)
End Try

'clean up is important so that references aren't left in memory
Try
If Not pptApp Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(pptApp)
End If
If Not rng Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(rng)
End If
If Not shp Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(shp)
End If
If Not target Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(target)
End If

Catch ex As Exception
'just eat it at this point
MsgBox("PPT Clean UP ERror: " & ex.Message)
End Try
End Sub



  #5  
Old December 8th, 2004, 02:57 PM
C Williams
external usenet poster
 
Posts: n/a
Default

Thank you, Ken. I'm kicking myself for that one because I WAS garbage
collecting earlier and I removed it for testing reasons but then forgot
to put it back in.

Thanks!

Ken Tucker [MVP] wrote:
Hi,

Add GC.Collect after you release the com objects.

Ken
----------------


"C Williams" wrote in message
news:RNotd.5342$Wy.250@trndny06...
Hi,

I am writing some VB.NET code that compiles to a dll. There is some
code within it that manipulates Powerpoint 2003.

The dll I am writing is for smart tags, and I am having trouble because
sometimes Powerpoint is remaining running (powerpnt.exe in Task
Manager). One action of my smart tags calls InsertChart (code below).
The designated line causes powerpoint to remain running even after the
user has manually closed the program--when that line is commented out,
powerpoint exits successfully.

Some quick testing I have done indicates that when my code changes the
active presentation (and would require a save), powerpoint doesn't exit.
If I don't actually change the presentation, it exits fine. (I
replaced the troublesome line below with one that changed the text of a
text box and had the same problem.)

If anyone has some insight into what's going on and how I need to
properly release my references to Powerpoint, I would be most
appreciative!

Thanks!

-Casey

'target is of type Powerpoint.TextRange
Public Sub InsertChart(ByVal target As Object, ByVal imagePath As
String) Implements IOfficeInteract.InsertChart
Dim pptApp As PowerPoint.Application
Dim rng As PowerPoint.TextRange
Dim shp As PowerPoint.Shape

Try
'try to grab powerpoint from target
rng = DirectCast(target, PowerPoint.TextRange)
pptApp = rng.Application


*****THE FOLLOWING LINE CAUSES THE PROBLEM. WHEN IT ISN'T COMMENTED,
POWERPOINT REMAINS RUNNING, WHEN IT IS COMMENTED, POWERPOINT CLOSES
SUCCESSFULLY ********
'shp =
pptApp.ActiveWindow.Selection.SlideRange.Shapes.Ad dPicture(imagePath, _
' Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoTrue, _
' 0, 0, 100, 100)

**********************

Catch ex As Exception
MsgBox("PPT:Error inserting chart:" & ex.Message)
End Try

'clean up is important so that references aren't left in memory
Try
If Not pptApp Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(pptApp)
End If
If Not rng Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(rng)
End If
If Not shp Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(shp)
End If
If Not target Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(target)
End If

Catch ex As Exception
'just eat it at this point
MsgBox("PPT Clean UP ERror: " & ex.Message)
End Try
End Sub


  #6  
Old January 3rd, 2005, 03:37 PM
WillRead
external usenet poster
 
Posts: n/a
Default

Hi C Williams,

You are getting close with the previous suggestions, but PowerPoint does not
like to give up without a fight. Use the following set of code at the end of
your method:

ppApp.Quit()
ppApp = DBNull.Value
GC.Collect
GC.WaitForPendingFinalizers()
GC.Collect
GC.WaitForPendingFinalizers()

(then the end of your Try -- Catch -- End Try

One needs to do the Garbage Collection Collect and WaitForPendingFinalizers
methods twice to make sure it clears out everything. Sometimes it does not.

Get a copy of Andrew Whitechapel's book "Microsoft .Net Development for
Microsoft Office", MicrosoftPress, ISBN 0-7356-2132-2. While the book is
heavy on Word and Excel and very light on PowerPoint, Whitechapel does a very
good job of explaining the need for good and complete garbage collection when
using the Office applications.

Good luck and enjoy.

Will
"C Williams" wrote:

Hi,

I am writing some VB.NET code that compiles to a dll. There is some
code within it that manipulates Powerpoint 2003.

The dll I am writing is for smart tags, and I am having trouble because
sometimes Powerpoint is remaining running (powerpnt.exe in Task
Manager). One action of my smart tags calls InsertChart (code below).
The designated line causes powerpoint to remain running even after the
user has manually closed the program--when that line is commented out,
powerpoint exits successfully.

Some quick testing I have done indicates that when my code changes the
active presentation (and would require a save), powerpoint doesn't exit.
If I don't actually change the presentation, it exits fine. (I
replaced the troublesome line below with one that changed the text of a
text box and had the same problem.)

If anyone has some insight into what's going on and how I need to
properly release my references to Powerpoint, I would be most
appreciative!

Thanks!

-Casey

'target is of type Powerpoint.TextRange
Public Sub InsertChart(ByVal target As Object, ByVal imagePath As
String) Implements IOfficeInteract.InsertChart
Dim pptApp As PowerPoint.Application
Dim rng As PowerPoint.TextRange
Dim shp As PowerPoint.Shape

Try
'try to grab powerpoint from target
rng = DirectCast(target, PowerPoint.TextRange)
pptApp = rng.Application


*****THE FOLLOWING LINE CAUSES THE PROBLEM. WHEN IT ISN'T COMMENTED,
POWERPOINT REMAINS RUNNING, WHEN IT IS COMMENTED, POWERPOINT CLOSES
SUCCESSFULLY ********
'shp =
pptApp.ActiveWindow.Selection.SlideRange.Shapes.Ad dPicture(imagePath, _
' Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoTrue, _
' 0, 0, 100, 100)

**********************

Catch ex As Exception
MsgBox("PPT:Error inserting chart:" & ex.Message)
End Try

'clean up is important so that references aren't left in memory
Try
If Not pptApp Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(pptApp)
End If
If Not rng Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(rng)
End If
If Not shp Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(shp)
End If
If Not target Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(target)
End If

Catch ex As Exception
'just eat it at this point
MsgBox("PPT Clean UP ERror: " & ex.Message)
End Try
End Sub

  #7  
Old January 3rd, 2005, 07:07 PM
WillRead
external usenet poster
 
Posts: n/a
Default

One correction to my previous listing of 1/3/2005:

Change line 2 from ppApp = DBNull.Value to ppApp = Nothing

ppApp = DBNull.Value will cause an InvalidCastException. Of course, Option
Strict turned on will catch the casting exceptions.

Will



"WillRead" wrote:

Hi C Williams,

You are getting close with the previous suggestions, but PowerPoint does not
like to give up without a fight. Use the following set of code at the end of
your method:

ppApp.Quit()
ppApp = DBNull.Value
GC.Collect
GC.WaitForPendingFinalizers()
GC.Collect
GC.WaitForPendingFinalizers()

(then the end of your Try -- Catch -- End Try

One needs to do the Garbage Collection Collect and WaitForPendingFinalizers
methods twice to make sure it clears out everything. Sometimes it does not.

Get a copy of Andrew Whitechapel's book "Microsoft .Net Development for
Microsoft Office", MicrosoftPress, ISBN 0-7356-2132-2. While the book is
heavy on Word and Excel and very light on PowerPoint, Whitechapel does a very
good job of explaining the need for good and complete garbage collection when
using the Office applications.

Good luck and enjoy.

Will
"C Williams" wrote:

Hi,

I am writing some VB.NET code that compiles to a dll. There is some
code within it that manipulates Powerpoint 2003.

The dll I am writing is for smart tags, and I am having trouble because
sometimes Powerpoint is remaining running (powerpnt.exe in Task
Manager). One action of my smart tags calls InsertChart (code below).
The designated line causes powerpoint to remain running even after the
user has manually closed the program--when that line is commented out,
powerpoint exits successfully.

Some quick testing I have done indicates that when my code changes the
active presentation (and would require a save), powerpoint doesn't exit.
If I don't actually change the presentation, it exits fine. (I
replaced the troublesome line below with one that changed the text of a
text box and had the same problem.)

If anyone has some insight into what's going on and how I need to
properly release my references to Powerpoint, I would be most
appreciative!

Thanks!

-Casey

'target is of type Powerpoint.TextRange
Public Sub InsertChart(ByVal target As Object, ByVal imagePath As
String) Implements IOfficeInteract.InsertChart
Dim pptApp As PowerPoint.Application
Dim rng As PowerPoint.TextRange
Dim shp As PowerPoint.Shape

Try
'try to grab powerpoint from target
rng = DirectCast(target, PowerPoint.TextRange)
pptApp = rng.Application


*****THE FOLLOWING LINE CAUSES THE PROBLEM. WHEN IT ISN'T COMMENTED,
POWERPOINT REMAINS RUNNING, WHEN IT IS COMMENTED, POWERPOINT CLOSES
SUCCESSFULLY ********
'shp =
pptApp.ActiveWindow.Selection.SlideRange.Shapes.Ad dPicture(imagePath, _
' Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoTrue, _
' 0, 0, 100, 100)

**********************

Catch ex As Exception
MsgBox("PPT:Error inserting chart:" & ex.Message)
End Try

'clean up is important so that references aren't left in memory
Try
If Not pptApp Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(pptApp)
End If
If Not rng Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(rng)
End If
If Not shp Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(shp)
End If
If Not target Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComO bject(target)
End If

Catch ex As Exception
'just eat it at this point
MsgBox("PPT Clean UP ERror: " & ex.Message)
End Try
End Sub

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
open Powerpoint main window and display a PPT file with automation David Powerpoint 0 December 6th, 2004 08:57 PM
PowerPoint to Excel link issues DrLostinExcel Powerpoint 5 November 19th, 2004 03:33 PM
PowerPoint Live's Tell A Friend Program Rick Altman Powerpoint 0 August 25th, 2004 03:05 PM
Running Powerpoint Viewer 2003 inside IE TAJ Simmons Powerpoint 2 August 24th, 2004 04:25 PM
Playing powerpoint in Internet Explorer with Viewer Shannon Thompson Powerpoint 1 June 4th, 2004 12:02 AM


All times are GMT +1. The time now is 03:45 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.