Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vba not releasing outlook process???

Status
Not open for further replies.

sedgely

Technical User
Feb 21, 2002
406
GB
Right, i have my code that creates and saves a txt file then mails the text file using outlook. all works fine EXCEPT... when running on the server which uses outlook 2000 it will run once, but the second time it fails. i've looked in the process list in task manager and it appears that something is "holding on" to the outlook.exe process, if i manually kill the process the script works (once). anyone any ideas how to kill the outlook process from within the excel vba?

Cheers, Craig
Si fractum non sit, noli id reficere
 
....and your code is.......


are you destroying your Outlook variable properly at the end of your code ???

e.g. set appOutlook = nothing

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Geoff
You may recognise some of this code from previous help you have given me...
Code:
Function export()

'----------mail--------
Dim OA As Object
Dim MI As Object
    Const olMailItem = 0
    Set OA = CreateObject("Outlook.Application")
    Set MI = OA.CreateItem(olMailItem)
Dim subject As String
Dim body As String
    subject = "Baseline performance info"
    body = "The attached file is the baseline Performance information for yesterday.<br> This is an automated email, please <b><font color=""red"">DO NOT REPLY</font></b>.<p>"
'--------------------------
‘code to create and save files

'------------mail-----------
With MI
  .To = "me@somewhere.com”
  .subject = subject
  .htmlbody = body
  .Attachments.Add filename
  .Send
End With
'-----------------------------

End Function

it works fine and sends the mail as expected but does not "kill" the outlook process


Cheers, Craig
Si fractum non sit, noli id reficere
 
Add the following at the end of your function:
Set MI = Nothing
OA.Quit
Set OA = Nothing

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
ditto PHV - hence my question before about destroying objects

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Mornin' Guys
Have tried that but it is still holding onto the process, if i keep running the code it completes OK but just creates a new outlook process every time. Any more ideas?
The code is now
Code:
Function export()

'----------mail--------
Dim OA As Object
Dim MI As Object
    Const olMailItem = 0
    Set OA = CreateObject("Outlook.Application")
    Set MI = OA.CreateItem(olMailItem)
Dim subject As String
Dim body As String
    subject = "Baseline performance info"
    body = "The attached file is the baseline Performance information for yesterday.<br> This is an automated email, please <b><font color=""red"">DO NOT REPLY</font></b>.<p>"
'--------------------------
‘code to create and save files

'------------mail-----------
With MI
  .To = "me@somewhere.com”
  .subject = subject
  .htmlbody = body
  .Attachments.Add filename
  .Send
End With
'-----------------------------

Set MI = Nothing
OA.Quit
Set OA = Nothing 

End Function


Cheers, Craig
Si fractum non sit, noli id reficere
 
UPDATE!!!

I think the problem may be related more to the OS or version of outlook. When i run the code on my local machine under XP and Outlook 2003 there is no problem, but when i run it on the server under W2k and Outlook 2k that is when the problem occurs.

Cheers, Craig
Si fractum non sit, noli id reficere
 
rather than using CreateObject, have a look at the helpfiles for GETobject

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 

There are some issues with the Outlook process (certainly in 2K) not terminating properly. I believe they may be fixed if you are fully patched (but don't quote me on that!).

It may be some (small) consolation to know that Outlook is a single instance applicatiion and although there are some minor bizarre side effects with the security model (which you will not have with an unpatched 2K version), creating (or trying to create) an Outlook object will give you a reference to the running one if there is one so you will not be leaving a trail of processes in memory

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Tony
I think you're right on there, even opening and closing Outlook manually leaves the process open on the 2k servers. But I'm not sure about the reference to the running process, as if I open and close Outlook several times in succession then check task manager there are several instances of Outlook.exe in the processes list. I have had a word with our techies and they are going to install Outlook 2003 this afternoon, maybe that will solve it or is it more to do with Windows 2k?

Cheers, Craig
Si fractum non sit, noli id reficere
 
Thanks Craig,

Interesting that the orphan processes are not recognised as Outlook applications - I just assumed they would be.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top