Sie sind auf Seite 1von 2

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) Dim bCancelSend As Boolean Dim sTextToSearch As String Dim sKeyWords

As String Dim vKeyWords() As String Dim iStartOfQuote As Long Dim iAttachmentCount As Long Dim i As Long If TypeName(Item) <> "MailItem" Then Exit Sub 'Add keywords/phrases here. Use lowercase words in the following array. sKeyWords = "attach;attached;attachment;enclosed;here's;here it is;enclosed;in clude;PFA;pfa;enclose;included;please find" 'CHECK FOR BLANK SUBJECT LINE If Item.Subject = "" Then bCancelSend = MsgBox("This message does not have a subject." & vbNewLine & _ "Do you wish to continue sending anyway?", _ vbYesNo + vbExclamation, "No Subject") = vbNo End If 'CHECK BODY AND SUBJECT FOR ATTACMENT KEYWORDS. 'Set TextToSearch variable to message Body based 'on message type and find start of quoted text. Select Case Item.BodyFormat Case olFormatHTML iStartOfQuote = InStr(Item.HTMLBody, "<DIV class=OutlookMessageHeader") 1 sTextToSearch = Item.HTMLBody Case olFormatRichText iStartOfQuote = InStr(Item.Body, "________________________________________ _____") - 1 sTextToSearch = Item.Body Case olFormatPlain iStartOfQuote = InStr(Item.Body, "-----Original Message-----") - 1 sTextToSearch = Item.Body End Select 'Adjust TextToSearch if there is quoted text If iStartOfQuote > 0 Then sTextToSearch = Left(sTextToSearch, iStartOfQuote) 'Add Subject to the search text if not a Reply If Left(Item.Subject, 3) <> "RE:" Then sTextToSearch = Item.Subject & " " & sTextToSearch End If 'Change to all lowercase for string comparison sTextToSearch = LCase(sTextToSearch) 'Replace undesired characters with spaces to help with ExactMatch function sTextToSearch = Replace(sTextToSearch, ",", " ") sTextToSearch = Replace(sTextToSearch, ".", " ") sTextToSearch = Replace(sTextToSearch, "?", " ") sTextToSearch = Replace(sTextToSearch, "!", " ") sTextToSearch = Replace(sTextToSearch, Chr(34), " ") 'quotes sTextToSearch = Replace(sTextToSearch, "<", " ") 'beginning of html tag sTextToSearch = Replace(sTextToSearch, ">", " ") 'end of html tag sTextToSearch = Replace(sTextToSearch, "&", " ") 'beginning of html Character Entities sTextToSearch = Replace(sTextToSearch, ";", " ") 'end of html Character Entit ies 'Start the search

If iAttachmentCount = 0 Then vKeyWords = Split(sKeyWords, ";") For i = LBound(vKeyWords) To UBound(vKeyWords) If InStr(sTextToSearch, vKeyWords(i)) > 0 Then If StrExactMatch(sTextToSearch, vKeyWords(i)) Then bCancelSend = MsgBox("It appears you were going to send an attachmen t but nothing is attached." & vbNewLine & _ "Do you wish to continue sending anyway?" & vbN ewLine & vbNewLine & _ "Word/Phrase found: " & vKeyWords(i), _ vbYesNo + vbExclamation, "Attachment Not Found" ) = vbNo Exit For End If End If Next i End If 'Cancel sending message if answered yes to either message box. Cancel = bCancelSend End Sub

Function StrExactMatch(sLookIn As String, sLookFor As String) As Boolean '- Add padding to sLookin in case sLookfor is at ' the very beginning or very end of the sLookIn. '- Add padding to sLookFor to ensure an exact match StrExactMatch = InStr(" " & sLookIn & " ", " " & sLookFor & " ") > 0 End Function

Das könnte Ihnen auch gefallen