Click here to Skip to main content
15,888,124 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

VB
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
Posted
Comments
Please debug and check line by line. You will surely come to know the issue.
archies_gall 23-Aug-13 0:00am    
Hi,

I am not able to debug the code. When i press F8 or try to click Debug in outlook nothing happens :(
so wanted to whats wrong in the code

1 solution

Your code looks good, but you need to know something... It is hard to answer in few words, so i would suggest you to read below articles:
Understanding Events in Outlook[^]
Working with Outlook events[^]
Using events with Automation[^] - the most important!
Using Outlook Visual Basic for Applications to respond to Outlook events[^]
Understanding VBA in Outlook[^]
Getting Started with VBA in Outlook 2010[^]
 
Share this answer
 
Comments
archies_gall 5-Jan-14 0:54am    
Maciej Los 5-Jan-14 5:01am    
You're welcome ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900