Hi,
I have searched the below code for giving reminder if email is sent without attachement if we use words like attached, enclosed, pfa, etc.
I have written this code in ThisOutlookSession of outlook.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim intIn As Long
intIn = 0
Dim wrds As String
strBody = LCase(Item.Subject) & LCase(Item.Body)
Set Rgx = CreateObject("vbscript.regexp")
Rgx.Pattern = wrds
Rgx.Global = True
Rgx.IgnoreCase = True
Set allMatches = Rgx.Execute(strBody)
intLength = InStr(1, strBody, "from:")
If intLength = 0 Then intLength = Len(strBody)
If intIn = 0 Then intIn = InStr(1, Left(strBody, intLength), "pfa")
If intIn = 0 Then intIn = InStr(1, Left(strBody, intLength), "PFA")
If intIn = 0 Then intIn = InStr(1, Left(strBody, intLength), "attached")
If intIn = 0 Then intIn = InStr(1, Left(strBody, intLength), "enclosed")
If intIn = 0 Then intIn = InStr(1, Left(strBody, intLength), "enclosing")
If intIn = 0 Then intIn = InStr(1, Left(strBody, intLength), "attachment")
If intIn = 0 Then intIn = InStr(1, Left(strBody, intLength), "attach")
intAttachCount = Item.Attachments.Count
If intIn > 0 And intAttachCount <= intStandardAttachCount Then
m = MsgBox("It looks like you forgot to attach a file... " _
& vbNewLine & vbNewLine & _
"Do you still want to send this message? ", _
vbYesNo + vbDefaultButton2 + vbExclamation + vbMsgBoxSetForeground, "Attachment Missing?")
If m = vbNo Then
Cancel = True
GoTo ExitSub
End If
End If
ExitSub:
Set Item = Nothing
strBody = ""
Exit Sub
End Sub
The code was working fine.Infact it works only for sometime while testing the code. After sometime it stops working.
When i try this same code on other pc it fails.Any help appreciated.
Regards,
Archie