PDA

View Full Version : Monitoring send/recieve



clvestin
11-16-2006, 09:50 AM
I'm sending mail via excel. I have a reference to the Outlook library.
However, the mail does not send until Outlook is physically opened.
I can open Outlook via my excel sheet
Application.ActivateMicrosoftApp xlMicrosoftMail

but how can i verify(test) if the Send/recieve operation has taken place and thus safely close Outlook and proceed??

clvestin
12-07-2006, 01:24 PM
OK-kind of a fix

Dim objOLapp As Object 'New Outlook.Application
Dim objmailitem As Object 'Outlook.MailItem
'Dim myrecip As Object 'Outlook.Recipient
'dim withevents mysync as outlook.syncobject

Set objOLapp = CreateObject("Outlook.Application")
Set objOLapp = New Outlook.Application

Set objmailitem = objOLapp.CreateItem(olMailItem)
Application.ActivateMicrosoftApp xlMicrosoftMail
'Application.Visible = False
'Application.EnableEvents

With objmailitem
.To = "joe"
.Subject = "Report"
.Attachments.Add "report.xls"
'.Display
.Send
End With

objOLapp.Session.SyncObjects.Item(1).Start

Outlook.Application.Quit

Set objOLapp = Nothing
Set objmailitem = Nothing
Set myrecip = Nothing


Syncing the object forces the send. Then in exiting, a dialog box remains for 30 seconds, giving enough time for the Send/Receive.