Office application object problem

  • Thread starter Thread starter sajin
  • Start date Start date
S

sajin

Hi all,

I'am trying to create object of Excel and powerpoint through my VB.Net
2005 application. When user close the excel or powerpoint it's instance

remains in the task manager.
I used ReleaseComObject because of which excel instance now goes trough
task manager , but same dosen't work with the Powerpoint object.
Any solution?
- Thanks
-Sajin
 
sajin said:
Hi all,

I'am trying to create object of Excel and powerpoint through my VB.Net
2005 application. When user close the excel or powerpoint it's instance

remains in the task manager.
I used ReleaseComObject because of which excel instance now goes trough
task manager , but same dosen't work with the Powerpoint object.
Any solution?
- Thanks
-Sajin

A simple test would be to create a new project, create two simple objects -
one Powerpoint instance, one Excel instance, release them and see if they
still hang around. I think that probably they will dissapear from Task
Manager. I suspect you have a reference to an instance of an object
returned from Powerpoint still loitering in your run somewhere. Are you
calling any methods on the office objects that return objects (like fields,
or selections or suchlike)? Those are reference counted and also need to be
released, not just the application instances.



Robin
 
Hi,
After doing ReleaseCom also still the instance exists in the task
manager , this is the code i am using
***********************************************************************************
Dim filepath As String

If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK
Then
filepath = OpenFileDialog1.FileName
End If

PowerApp = New PowerPoint.Application

PowerApp.Visible = Office.MsoTriState.msoCTrue

PowerApp.Presentations.Open(filepath,
Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse,
Office.MsoTriState.msoTrue)

PowerApp.ActiveWindow.View.GotoSlide(index:=PowerApp.ActivePresentation.Slides.Add(index:=1,
Layout:=PowerPoint.PpSlideLayout.ppLayoutTitle).SlideIndex)
' only close PowerPoint if there are no open Presentations
If (PowerApp.Presentations.Count <= 0) Then
PowerApp.Quit()
End If

***********************************************************************************
 
Hi,
After doing ReleaseCom also still the instance exists in the task
manager , this is the code i am using
***********************************************************************************
Dim filepath As String

If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK
Then
filepath = OpenFileDialog1.FileName
End If

PowerApp = New PowerPoint.Application

PowerApp.Visible = Office.MsoTriState.msoCTrue

PowerApp.Presentations.Open(filepath,
Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse,
Office.MsoTriState.msoTrue)

PowerApp.ActiveWindow.View.GotoSlide(index:=PowerApp.ActivePresentation.Slides.Add(index:=1,
Layout:=PowerPoint.PpSlideLayout.ppLayoutTitle).SlideIndex)
' only close PowerPoint if there are no open Presentations
If (PowerApp.Presentations.Count <= 0) Then
PowerApp.Quit()
End If

***********************************************************************************
 
PowerApp.ActiveWindow.View.GotoSlide(index:=PowerApp.ActivePresentation.Slides.Add(index:=1,
Layout:=PowerPoint.PpSlideLayout.ppLayoutTitle).SlideIndex)
' only close PowerPoint if there are no open Presentations
If (PowerApp.Presentations.Count <= 0) Then
PowerApp.Quit()
End If

Don't quote me but I think possibly PowerApp.ActivePresentation.Slides is a
reference. Try fetching the reference (PowerApp.ActivePresentation.Slides)
into a variable and then issuing the Add in a new statement, then releasing
the variable you allocated for the Slides collection. Also be aware if Add
returns a reference (I don't think it does, but just in case). You should
be very wary of compound statements like this when using interop, because
sometime references are created that you don't see very easily.
 
Hi when I use a word object I always "dispose" of it like this and then
nothing remains in the taskmanager

'open word class
Dim oWord As New Word.ApplicationClass

'open a document
Dim oDoc As Word.Document

'add a template to it
oDoc = oWord.Documents.Add(Application.StartupPath & "\yourfile.dot")

'do the work
....

'release eveything
oDoc.Close()
oDoc = Nothing
oWord.Quit(False)
oWord = Nothing


hope this helps,

Greetz, Peter
 
Back
Top