Outllok Automation

J

JCP

I created a function to attach file.
The function attaches the file and displays the outlook for the user. He can
add address or write something in the body text. When he finishes, click send
button and the email is gone and outlook window is closed.
Apparently it works well.

However, yesterday I received a message showing, the memory is low.
I open task manager and I saw many outlook instances open.

I verify the outlook still running. I set objOutlookMsg = Nothing and
Set objOutlook = Nothing

Is it possible somebody tell me what is wrong in my function?
Thanks a lot.
jcp
-----------------------
Here you are the function to attach files.

Function EmailAttachFile()
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim AttachFile As String

AttachFile = "C:\Test.doc"

Set objOutlook = CreateObject("Outlook.Application") ' Create the
Outlook session.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem) ' Create
the message.

With objOutlookMsg
.To = "jose perdigao"
.CC = ""
.BCC = ""
.Subject = "This is a test"
.Body = "Tell me if it works"
End With

If Dir(AttachFile) <> "" Then objOutlookMsg.Attachments.add AttachFile

objOutlookMsg.Display

Set objOutlookMsg = Nothing
Set objOutlook = Nothing

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top