C
C Williams
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.AddPicture(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.ReleaseComObject(pptApp)
End If
If Not rng Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(rng)
End If
If Not shp Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(shp)
End If
If Not target Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(target)
End If
Catch ex As Exception
'just eat it at this point
MsgBox("PPT Clean UP ERror: " & ex.Message)
End Try
End Sub
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.AddPicture(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.ReleaseComObject(pptApp)
End If
If Not rng Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(rng)
End If
If Not shp Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(shp)
End If
If Not target Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(target)
End If
Catch ex As Exception
'just eat it at this point
MsgBox("PPT Clean UP ERror: " & ex.Message)
End Try
End Sub