Closing outlook

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I am using outlook to display and send new mail message from within vb.net.
What is the correct way to close outlook after I am done? If I use
outlookapp.quit then any running outlook copy also closes which is
inconvenient for user. If I use outlookapp = nothing then strange things
happen afterwards, such as the mail message not being sent when pressing
Send button. Is there a way to close only the instance of outlook that was
opened from within vb.net and not the main outlook app which was run
separately?

Thanks

Regards
 
Hi John
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject
(outlookapp)

Kind Regards
Jorge
 
Tried that but when I try to send a second mail I get the error;

Unhandled Exception: System.Reflection.TargetInvocationException: Exception
has been thrown by the target of an invocation. --->
System.Runtime.InteropServices.InvalidComObjectException: COM object that
has been separated from its underlying RCW can not be used.

Here is the jist of my code;

Private WithEvents OutlookApp As Outlook.Application
Private WithEvents em As Outlook.MailItem

OutlookApp = New Outlook.Application '<=== I am getting the above error
here.
em = OutlookApp.CreateItemFromTemplate(EmailTemplate)

em.To = "(e-mail address removed)"
em.Display(True)

' em = Nothing

' OutlookApp = Nothing ' This caused straneg effects
' OutlookApp.Quit() ' This caused outlook app to close too
System.Runtime.InteropServices.Marshal.ReleaseComObject(OutlookApp) ' This
is what I am trying now
 
Back
Top