Outlook to check for specific text

Status
Not open for further replies.

sem

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
Dear All,

While sending an email I need a outlook code to check a specific text in the body line and if found it do not send the email and just pop up the number of times the text found in the email.

Is it possible to derive a code for this ?
 

sem

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
anyone who can help me on this...
 

Dan_W

Member
Outlook version
Outlook 2016 32 bit
Email Account
Outlook.com (as MS Exchange)
Hi Sem

The Slipstick website helpfully has the answer for you, in parts. First, check out the "Checking for missing attachments before sending a message" article. Here, you will see the following code snippet:

Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
   If InStr(1, Item.Body, "attach", vbTextCompare) > 0 Then
        If Item.Attachments.Count = 0 Then
          answer = MsgBox("There's no attachment, send anyway?", vbYesNo)
          If answer = vbNo Then Cancel = True
        End If
   End If
End Sub
The important part of the code is If InStr(1, Item.Body, "attach", vbTextCompare) > 0 Then. The INSTR function will check the body of the email for the word "attach"; if it finds the word, it will return the location of the character in that word within the string being search (item.body). However, this won't give you the number of instances that the search term appears in the email body. You would need to add more code if you wanted to use this approach.

Second, an alternative approach would be to use regular expressions to parse the body of the email. You should look at "Use RegEx to extract text from an Outlook email message". I would suggest putting your code in the Application_ItemSend event, as above, then using the RegEx test method to see if the word/phrase exists in the email body. If it does, then execute the regex, and get the number of matches.

I hope that helps.
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
N Outlook - check sent items if messages sent from a specific account move it to another mailbox sent Using Outlook 3
C Custom Outlook Form - Populate Information from Radio Button / Check Box Using Outlook 0
O Outlook 2016 This rule will only run when you check your email in Outlook.... Using Outlook 4
Potty Ash MS Outlook 2010 custom form - validation or formula to request user to check a checkbox Outlook VBA and Custom Forms 16
R Macro to check file name with outlook address book Outlook VBA and Custom Forms 0
R Outlook 2010 Modify Style "Do not check spelling or grammar" not saving Outlook VBA and Custom Forms 0
R Outlook Custom form check if there an attachment Outlook VBA and Custom Forms 2
T Outlook 2007 forms: Check boxes and free text boxes not retaining data Using Outlook 1
M Outlook Rules check for new line character Using Outlook 1
D Inserting check boxes in task requests Outlook 2007 Using Outlook 2
E Outlook 2010 won't check for email. Using Outlook 2
P Spell check greyed out in Outlook 2010 Using Outlook 2
B In Contact Properties of Outlook 2010, it does not allow me to check the check box " Show this folde Using Outlook 2
B Re: In Contact Properties of Outlook 2010, it does not allow me to check the check box " Show this f Using Outlook 2
P Outlook deletes my email account passwords even when I check 'save password' box Using Outlook 2
J OUTLOOK 2010 Does not check E-mail when off-line Using Outlook 7
K Removing words from the Spell Check Dictionary on Outlook 10 Using Outlook 2
S How do I set up more than 1 email account for Outlook 2007. Have recently purchased a laptop and want to be able to check all emails that come into t Using Outlook 2
T Need to be able to check my microsoft outlook emails via my blackberry Using Outlook 1
O Spell Check on by default in Outlook Web App Using Outlook 1
H Outlook 2010 IMAP folders in Favorites and automatic mail check. Using Outlook 5
J Change Outlook Express spell check language from French to English Using Outlook 1
A Outlook Express 2007 defaults to French spell check only Using Outlook 1
C Spell Check just stopped working in Outlook Standard 2007 Using Outlook 2
C Need to know how to allow a hyperlink to work from and email in outlook 2010. Currently they are blocked and telling me to check with administrator. Using Outlook 3
S outlook spelling check subject different from body text (english / portuguese) Using Outlook 1
W setup 2007 outlook to check a metnet.edu account Using Outlook 1
C Spell Check Causes Crash of Outlook 2007 Using Outlook 2
J My outlook express spell check is in French and it won't let me change it to english. Using Outlook 2
H Outlook 2007 spell check does not ignore original email message Using Outlook 1
G Re: Microsoft Outlook has Stopped Working - Windows can check online or Stop the Program Using Outlook 3
S Outlook 2007, spell check stops working Using Outlook 1
L I work for a corporation that uses outlook. I can check my mail with outlook web access, but would like to use outlook for my company mail. Is it poss Using Outlook 2
C All of a sudden I can't open Microsoft Outlook 2007 to check email. Using Outlook 1
M Outlook 2007: Why the English UK Dictionary is not working during spell check? Using Outlook 4
D Outlook crashes when spell check is used Using Outlook 1
B Outlook 2010 does not spell check even spell check is checked in Outlook option. Using Outlook 1
J Spell Check not working on Outlook 2007 Using Outlook 7
W How to sign in outlook 2003 from another computer to check my email and send messages Using Outlook 2
J Outlook 2010 Beta spell check not working Using Outlook 8
G Outlook rule check for messages not received Outlook VBA and Custom Forms 2
E Outlook could not create the work file. Check the temp environment variable Using Outlook 8
D microsoft outlook has stopped working, close program, windows will check for solution Using Outlook 9
H out to check whether outlook configured or not Outlook VBA and Custom Forms 1
M Outlook 2016 Outlook randomly unhides from taskbar Using Outlook 0
X Using Outlook 2013 and Outlook 365 Using Outlook 1
V Date and/or time error in Outlook Form Outlook VBA and Custom Forms 0
D Sending email from Office 365 alias in Outlook Using Outlook 4
B Spam folder not showing in Outlook Using Outlook 5
ThinkToday Calculate reply time of outlook mail Using Outlook 1
Similar threads


















































Top