0

This code will end the process OUTLOOK.EXE from the Task Manager. If the user has already opened his Outlook separately, it will be also closed. That is not acceptable for the user.

Dim objOLApp As Outlook.Application
.
.
.
.
Call objOLApp.Quit()  
Call System.Runtime.InteropServices.Marshal.ReleaseComObject(objOLApp)   
objOLApp = Nothing

I found a solution by removing: Call objOLApp.Quit()

Now there is another problem. OUTLOOK.EXE won't terminate after closing the program and closing the Outlook windows (in case it is opened). I have to do (End Process) from Task Manager.

Any suggestions?

Community
  • 1
  • 1
user2235551
  • 1
  • 1
  • 3

1 Answers1

0

Automating Outlook is notoriously awkward, it's really meant to be a client application. Based on the fact your trying to close outlook I'm guessing you using it to maipulate an email box or contacts or calendar entries or something.

I would recommend you spend a few $ and use "Outlook Redemption"

If you really need to ensure outlook is closed the below way should work and should be fairly non-intrusive.

Sub CloseOutlook()
    Dim pros() As Process = Process.GetProcessesByName("Outlook")
    For Each p As Process In pros
        p.CloseMainWindow()
        If Not p.WaitForExit(15000) then ' wait up to 15sec to close
            Try 'force close below
                p.Kill() 'hazardous call.
            Catch ex As Exception

            End Try
        End If
    Next
End Sub
DarrenMB
  • 2,342
  • 1
  • 21
  • 26