Monday, April 09, 2007

Dan Evans' VBA Scripts - Outlook Attachment Checker etc

 

This macro checks for when you mention Attach in your email, and then prompts you if you forgot an attachment.  See posting for details on installation. 

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
' VBA program for Outlook, (c) Dan Evans. dan at danevans.co.uk
' Will check if your outgoing email mentions an attachment, but you've
' forgotten to attach it
' v1.03 of 10/8/04 - Modified to search through subject line as well as message body
' v1.02 of 16/10/02 - No change to code, but tested works with Outlook 2002 as well as Outlook 2000
' v1.01 of 23/9/01 - OK for "Attach" as well as "attach"
' v1.00 of 21/9/01 - Initial working version
Dim intRes As Integer
Dim strMsg As String
Dim strThismsg As String
Dim intOldmsgstart As Integer
intOldmsgstart = InStr(Item.Body, "-----Original Message-----")
' intOldmsgstart is the location of where old/re/fwd msg starts. Will be 0 if new msg
If intOldmsgstart = 0 Then
strThismsg = Item.Body + " " + Item.Subject
Else
strThismsg = Left(Item.Body, intOldmsgstart) + " " + Item.Subject
End If
' The above if/then/else will set strThismsg to be the text of this message only,
' excluding old/fwd/re msg
' IE if the original included message is mentioning an attachment, ignore that
' Also includes the subject line at the end of the strThismsg string
If InStr(LCase(strThismsg), "attach") > 0 Then
If Item.Attachments.Count = 0 Then
strMsg = "Dan Evans' Attachment Checker:" & Chr(13) & Chr(10) & "Your message mentions an attachment, but doesn't have one." & Chr(13) & Chr(10) & "Send the message anyway?"
intRes = MsgBox(strMsg, vbYesNo + vbDefaultButton2 + vbExclamation, "You forgot the attachment!")
If intRes = vbNo Then
' cancel send
Cancel = True
End If
End If
End If
End Sub

Source: Dan Evans' VBA Scripts - Outlook Attachment Checker etc

No comments: