Tapping in to the send event

  • Thread starter Thread starter ck
  • Start date Start date
C

ck

I am trying to tap in to the send event of the current mail item.
What am I doing wrong. I want a msgbox to pop up and confirm that I
would like to send the email. When I click send. Nothing happens.
Where am I going wrong? TIA ck

Dim ol As Outlook.Application
Set ol = New Outlook.Application

Sub objmail_Send(Cancel As Boolean)
Dim objmail As Outlook.MailItem
Set objmail = ol.ActiveInspector.CurrentItem
Dim i As Integer

i = MsgBox("Are you sure you want to send that message?", vbYesNo
+ vbQuestion, "Are you sure?")

If i = vbYes Then
Cancel = False
Else
Cancel = True
End If

End Sub
 
Your missing:

Public WithEvents objMail As Outlook.MailItem

This is taken from the Outlook VBA help file:

This Visual Basic for Applications (VBA) example uses the
Send event and sends an item with an automatic expiration
date. The sample code must be placed in a class module
such as ThisOutlookSession, and the SendMyMail procedure
must be called before the event procedure can be called
by Microsoft Outlook.

Public WithEvents myItem As Outlook.MailItem

Sub SendMyMail()
Set myItem = Outlook.CreateItem(olMailItem)
myItem.To = "Dan Wilson"
myItem.Subject = "Data files information"
myItem.Send
End Sub

Private Sub myItem_Send(Cancel As Boolean)
myItem.ExpiryTime = #2/2/2003 4:00:00 PM#
End Sub
 
Back
Top