0
  1. Run following code and check your Task Manager to see if the Excel and Outlook process exists:

    Imports Microsoft.Office.Interop
    
    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    
            'Kill all EXCEL.EXE's from Task Manager
            For Each prog As Process In Process.GetProcessesByName("EXCEL")
                prog.Kill()
            Next
    
            'Kill all OUTLOOK.EXE's from Task Manager
            For Each prog As Process In Process.GetProcessesByName("OUTLOOK")
                prog.Kill()
            Next
    
            'Open new EXCEL.EXE in the Task Manager
            Dim xlApp As New Excel.Application
    
            'Open new OUTLOOK.EXE in the Task Manager
            Dim olApp As New Outlook.Application
    
        End Sub
    
    End Class
    
  2. Close Form1

  3. Check your Task Manager and see that the Excel process doesn't exists but the Outlook process does.

Why does, within Task Manager, the Excel process not exist when I close Form1 but the Outlook process does?

Bugs
  • 4,491
  • 9
  • 32
  • 41

2 Answers2

0

try starting Excel like this:

Dim xlApp As New Process
xlApp.StartInfo.FileName = "filePath/excel.exe"
xlApp.Start

if that doest help, just try this to start an exe:

Process.Start("filePath\excel.exe")
Alex
  • 112
  • 10
0

I haven't been able to reproduce this issue you are having. The Outlook process does take a little longer to end but it does end.

That being said, there are better ways to close down these processes. As said in my comment, have a look at this answer which links to Siddharth Rout's bit of code.

First you would need to declare xlApp and olApp at class level. You would also need add the following method into your code:

Private Sub ReleaseObject(ByVal obj As Object)
    Try
        Dim intRel As Integer = 0
        Do
            intRel = System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
        Loop While intRel > 0
        obj = Nothing
    Catch ex As Exception
        obj = Nothing
    Finally
        GC.Collect()
    End Try
End Sub

You can then call this method when you are closing down your form:

Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
    xlApp.Quit()
    ReleaseObject(xlApp)

    olApp.Quit()
    ReleaseObject(olApp)
End Sub

Overall your code would look something similar to this:

Public Class Form1

    Private xlApp As Excel.Application
    Private olApp As Outlook.Application

    Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        'Open new EXCEL.EXE in the Task Manager
        xlApp = New Excel.Application

        'Open new OUTLOOK.EXE in the Task Manager
        olApp = New Outlook.Application

    End Sub

    Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        xlApp.Quit()
        ReleaseObject(xlApp)

        olApp.Quit()
        ReleaseObject(olApp)
    End Sub

    Private Sub ReleaseObject(ByVal obj As Object)
        Try
            Dim intRel As Integer = 0
            Do
                intRel = System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
            Loop While intRel > 0
            obj = Nothing
        Catch ex As Exception
            obj = Nothing
        Finally
            GC.Collect()
        End Try
    End Sub

End Class
Community
  • 1
  • 1
Bugs
  • 4,491
  • 9
  • 32
  • 41