DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: make outlook.exe process close properly

  1. #1
    Join Date
    Dec 2006
    Posts
    23

    make outlook.exe process close properly

    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
    ------------
    Code:
    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 = "m.Min@RorSncis.com"
            .CC = "ra@critdjume.com"
            .BCC = ""
            .Subject = "CABCALLS & CABLETTERS record counts for " & Format(Date, "mm/dd/yy")
            .HTMLBody = "Hello Pam:<br><br>" & _
                    "For " & Format(Date, "mm/dd/yy") & ":&nbsp;*&nbsp;*&nbsp;*&nbsp;*&nbsp;*# of Records<br>" & _
                    "CABLETTERS.TXT&nbsp;*&nbsp;*" & CABLETTERSlineCount & "<br>" & _
                    "CABCALLS.TXT&nbsp;*&nbsp;*&nbsp;*&nbsp;*" & 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
    ------------

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Try calling OutApp.Quit before you set OutApp = Nothing.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Dec 2006
    Posts
    23
    modifying the last few lines of the code like this worked well for me....thank you
    Code:
       VbSendKeys "Y"
        TimeDelay (4)
        Set OutMail = Nothing
        OutApp.Quit
        TimeDelay (4)
        Set OutApp = Nothing

  4. #4
    Join Date
    Mar 2005
    Location
    Los Angeles, Calif. AKA: Gangsta Yoda™
    Posts
    455
    Executing the OutApp.Quit after you destroy the object is backwards.

    OutApp.Quit
    Set OutApp = Nothing

    Should be the order of execution.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer code questions via PMs.
    Microsoft MVP 2006-2009
    Office Development FAQ (VBA, VB6, VB.NET, C#)
    Software Engineer MCP (VB6 & .NET)
    Reps & Rating PostsVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6Outlook Global Address List

Similar Threads

  1. Re: MAKE $$$$$$$$$$ FAST THIS REALLY WORKS
    By Mark Campisi in forum .NET
    Replies: 0
    Last Post: 07-14-2002, 04:05 PM
  2. How to make consistant site
    By tibbs in forum Architecture and Design
    Replies: 9
    Last Post: 03-01-2002, 03:12 AM
  3. Replies: 1
    Last Post: 04-21-2000, 11:43 AM
  4. Replies: 0
    Last Post: 04-12-2000, 12:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center