make outlook.exe process close properly

  • 13 years ago

    hello,
    I have some VB code that automatically composes an send an e-mail via Outlook 2002 and I've been having the problem of after the VB code executable has finished running the Outlook.exe process is left running in the background, which I can see when I look in the Processes tab of Windows Task Manager.  
    What changes do I have to do to the code to make the Outlook.exe process properly close after the e-mail has been sent and the VB code has finished executing?
    thanks in advance,
    david
    ------------




    Dim OutApp As Object
        Dim OutMail As Object
        Dim SigString As String
        Dim Signature As String

        Set OutApp = CreateObject("Outlook.Application")
        OutApp.Session.Logon
        Set OutMail = OutApp.CreateItem(0)

        'figure out how to randomize the number to go between 2 and whatever # I'm up to'
        SigString = "C:\Documents and Settings\Admin\Application Data\Microsoft\Signatures\dgr2.htm"

        If Dir(SigString) <> "" Then
            Signature = GetBoiler(SigString)
        Else
           Signature = "where's the signature?"
        End If

        On Error Resume Next
        With OutMail
            .To = "



















    [email protected]"
            .CC = "
    [email protected]"
            .BCC = ""
            .Subject = "CABCALLS & CABLETTERS record counts for " & Format(Date, "mm/dd/yy")
            .HTMLBody = "Hello Pam:<br><br>" & _
                    "For " & Format(Date, "mm/dd/yy") & ":&nbsp;#160;&nbsp;#160;&nbsp;#160;&nbsp;#160;&nbsp;#160;# of Records<br>" & _
                    "CABLETTERS.TXT&nbsp;#160;&nbsp;#160;" & CABLETTERSlineCount & "<br>" & _
                    "CABCALLS.TXT&nbsp;#160;&nbsp;#160;&nbsp;#160;&nbsp;#160;" & CABCALLSlineCount & "<br><br>" & Signature
            .Display
        End With

        On Error GoTo 0

        TimeDelay (4)
        AppActivate OutMail
        VbSendKeys "^{ENTER}"
        AppActivate OutMail
        VbSendKeys "%{F4}"
        AppActivate OutMail
        VbSendKeys "Y"

        Set OutMail = Nothing
        Set OutApp = Nothing
























Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“You can stand on the shoulders of giants OR a big enough pile of dwarfs, works either way.”