Outlook Automation Question

D

David C. Holley

A question has arisen in another forum about sending mail via Access. In
the course of answering that, I have a question for all.

Q1: Does OUTLOOK have to be open in order to actually send a MailItem?
I was under the impression that when you execute the .Send method that
the item was sent, instead it appears that the item ends up in the
OUTBOX waiting to be sent.

Q2: Is there a way to programically force OUTLOOK to process the mail
via VBA?
 
E

Eric Legault [MVP - Outlook]

1. Yes, you have to instantiate Outlook from another application by setting
a variable to New Outlook.Application. This causes the outlook.exe process
to load, but it won't actually display the application. This technique
causes the full Outlook to load:

Dim objOL As Outlook.Application
Dim objExp As Outlook.Explorer
Dim objNS As Outlook.NameSpace

Set objOL = New Outlook.Application
Set objNS = objOL.GetNamespace("MAPI")
Set objExp = objOL.Explorers.Add(objNS.GetDefaultFolder(olFolderInbox),
olFolderDisplayNormal)
objExp.Activate 'Set breakpoint here to watch Outlook appear

'Step over remaining statements to watch how Outlook closes and releases
memory
objExp.Close
Set objExp = Nothing

objOL.Quit
Set objOL = Nothing

2. Try this code sample:

To deliver a Microsoft Outlook item immediately (code sample):
http://www.outlookcode.com/d/code/sendnow.htm
 
Top