Greetings,
I forget to send attachments way too often, so while I was trying to figure out how VBA could help me, I stumbled upon this at sourceforge.net.
I noticed that the variables were not declared, so I changed that to the best of my ability (I know using Variant is frowned upon; what is the correct type for those below?)
I also noticed that it didnt check the subject line, so I added that.
Everything worked great until I restarted Outlook. Now it it seems that the macro doesnt even 'fire' when an email is sent (tried having a messagebox appear). again, all worked well until i restarted outlook!
This code is in the ThisOutlookSession. I have never tried to do anything with VBA in Outlook, so I suspect I am missing something silly...
Also, I am using Outlook 2003 - THANKS! tim
[vba]
Option Explicit
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Rem=======================================================
Rem
Rem PROJECT: CheckAttachment
Rem Fairtec (www.fairtec.at)
Rem
Rem COPYRIGHT Manfred Hofbauer FAIRTEC
Rem LICENSE GNU/PL
Rem
Rem AUTHORS: MHO: Manfred Hofbauer (opensource@fairtec.at)
Rem DESCRIPTION: a simple macro, that checks if you mentioned an attachment and
Rem didn't attach it to your mail
Rem
Rem Subversion Tags
Rem
Rem $Author: Manfred.Hofbauer $
Rem $LastChangedDate: 2005-08-26 10:00:38 +0200 (Fr, 26 Aug 2005) $
Rem $LastChangedRevision: 663 $
Rem $LastChangedBy: Tim Poynton $
Rem $Id: MacroCodeEN.txt 663 2005-08-26 08:00:38Z Manfred.Hofbauer $
Rem========================================================
Rem Code is just executed if it is a mail and there is nothing attached
If Item.Class = olMail And Item.Attachments.Count = 0 Then
'MsgBox ("macro works")
Dim arrKeywords As Variant
Dim sBoxQuestion As String
Dim sBoxTitle As String
Dim sMailText As String
Dim vAnswer As Variant
Dim sSubjectText As String
Dim i As Integer
Rem define keywords
arrKeywords = Array("ENCLOS", "ATTACH", "ENCLOSURE")
sBoxQuestion = "Shall the eMail be sent without an attachment " & _
"(an attachment was mentioned)?"
sBoxTitle = "Attachment Missing?"
sMailText = UCase(Item.Body)
sSubjectText = UCase(Item.Subject)
Rem compare mail-body with keywords
For i = 0 To UBound(arrKeywords)
If InStr(sMailText, arrKeywords(i)) > 0 _
Or InStr(sSubjectText, arrKeywords(i)) > 0 Then
vAnswer = MsgBox(sBoxQuestion, vbYesNo & vbDefaultButton2, sBoxTitle)
If vAnswer = vbNo Then
Cancel = True
Exit For
End If
End If
Next i
End If
End Sub
[/vba]