Search code examples
vb.netoutlook-object-model

VB.net 2005 Sending Emails With Outlook 2003


We currently use the following code to create an email in Outlook so that the user can type what they want in Outlook, then when the email is sent, the system prompts them to see if they would like to save the email.

            Dim objOutlook As Object
            Dim objMessage As Object
            Dim objInspector As Object

            If strEMail <> "" Then
                objOutlook = CreateObject("Outlook.Application")
                objMessage = objOutlook.CreateItem(0)
                objMessage.To = strEMail

                objInspector = objMessage.GetInspector
                objInspector.Display()

                While Not objInspector.CurrentItem Is Nothing
                End While

                frmSaveSentEmail.BringToFront()
                frmSaveSentEmail.ShowDialog()

The code works fine on Outlook 2003 as long as they are not using Word as their email editor. However, with Word set up as the email editor, the while loop that tests to see if the email object is closed never ends.

Is there a way to handle this differently so that it will work even with Word as the editor?


Solution

  • Ended up changing the loop to:

      While Not objOutlook.ActiveInspector Is Nothing
      End While
    

    This resolved the issue.