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 ?
 
anyone who can help me on this...
 
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.
Similar threads
Thread starter Title Forum Replies Date
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
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
H out to check whether outlook configured or not Outlook VBA and Custom Forms 1
G Outlook 2021 (New) doesn't respect default browser Using Outlook 1
B Outlook or iPhone turning tabs into spaces in Outlook Notes Using Outlook 1
P newly installed Office 365 includes OLD Outlook Using Outlook 6
R Outlook ribbon menu default? Using Outlook 7
H Spam email in Gmail not visible in Outlook Using Outlook 3
J How to transfer Win 10 Outlook to new Windows 11 pc? Using Outlook 9
J Renegade spam URL line displayed in old local Outlook 365 email title Using Outlook 3
G Reduce whitespace in Outlook desktop Contact Cards display Using Outlook 3
C Outlook classic via 365 Using Outlook 2
Dr. Demento Analogous Outlook code to read info into an array (or collection or whatever) Outlook VBA and Custom Forms 7
S Repair Outlook Using Outlook 8
V Outlook Form ListBox is not editable Outlook VBA and Custom Forms 2
F Outlook's contacts Using Outlook 1
D Outlook 2003 stopped dead Using Outlook 2
G Cannot receive emails from gmail account in Outlook 365 Using Outlook 1
E "Cannot display the folder. MS Outlook cannot access the specified file location" Using Outlook 8
P Outlook 2016 Working Offline Using Outlook 2
Rupert Dragwater Cannot reestablish gmail (email address) account in Outlook 365 Using Outlook 11
O Outlook 365 synchronisieren Exchange Server Administration 1
kburrows Outlook Classic - JPG files are corrupted when opened or saved Using Outlook 3
F Sync Outlook Calendar Using Outlook 0
G Change default font size in sticky notes - Outlook Desktop 2021 Using Outlook 2
C VBA in "New Outlook?" Using Outlook 0
D New Outlook with Business Basic Plans Using Outlook 0
D Outlook 2021 not working with Outlook 2003 installed Using Outlook 5
D Outlook 2003 stopped working - get they dialog box asking for username & Password Using Outlook 2
T Outlook 2021 hangs in close on taskbar occasionally Using Outlook 1
M Duplicate removal feature in Outlook 2021 is faulty Using Outlook 2
D.Moore Outlook COM addins source folder Using Outlook 12
P Removing Outlook 365 Account from Send/Receive Using Outlook 3
kburrows Outlook Automatically Merging Contacts Using Outlook 2
A Outlook 2016 Outlook 2016 vs. New Outlook Using Outlook 4
D Outlook Desktop App Email Software Using Outlook 0
efire9207 VBA Outlook Contacts Outlook VBA and Custom Forms 6
M Outlook not logging in to server Using Outlook 0
J Outlook macro to run before email is being send Outlook VBA and Custom Forms 3
R Outlook 2021 change view Using Outlook 2
K Outlook font corrupted in some point sizes, resets on close/open Using Outlook 2
J Is the Windows Outlook Tasks module really going to be gone? Using Outlook 6

Similar threads

Back
Top