Current location - Quotes Website - Personality signature - How to use VBA in OutLook 2010: when you finish writing an email and click send, determine whether there are attachments
How to use VBA in OutLook 2010: when you finish writing an email and click send, determine whether there are attachments

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

Dim myOlApp As New Outlook.Application

Dim myItem As Outlook.MailItem

Dim myAttachments As Outlook.Attachments

Dim cancelsend As Long

Set myItem = myOlApp.CreateItem(olMailItem)

Set myAttachments = myItem.Attachments

If myItem.Attachments.Count = 0 Then

cancelsend = MsgBox("Did you forget to paste the attachment?" & vbNewLine & vbNewLine & "Are you sure you want to send it?", _< /p>

vbYesNo + vbDefaultButton2 + vbQuestion, "Forgot to paste attachment prompt")

If cancelsend = vbNo Then Cancel = True

End If

End Sub