Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-02-2021, 08:39 AM
damaniam damaniam is offline Filter Messages Based on Phrase with Number in Content Windows 10 Filter Messages Based on Phrase with Number in Content Office 2019
Novice
Filter Messages Based on Phrase with Number in Content
 
Join Date: Nov 2013
Posts: 18
damaniam is on a distinguished road
Default Filter Messages Based on Phrase with Number in Content

So every day I get an email and it contains the phrase "Total Scrubbed Deferred: X". X represents any integer. The phrase may appear more than once in the same email, but not more than twice.



My objective is to have the emails that are received where X is = 0 simply be marked as read. For those where X is > 0 receive an alert window with whatever that day's phrase is. For example, if today's email reference "Total Scrubbed Deferred: 2" and further down "Total Scrubbed Deferred: 1", the alert window would show "Total Scrubbed Deferred: 2" "Total Scrubbed Deferred: 1".

I apologize if this is something that has already been answered and if so, I would appreciate someone pointing me in the correct direction of the solution. If this is a new question, thanks in advance to anyone for your assistance.
Reply With Quote
  #2  
Old 02-02-2021, 11:24 PM
gmayor's Avatar
gmayor gmayor is offline Filter Messages Based on Phrase with Number in Content Windows 10 Filter Messages Based on Phrase with Number in Content Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You need a script in conjunction with a rule that identifies the incoming messages e.g. as follows. Use the test macro with an existing message to test the script.

Code:
Option Explicit

Sub TestScrubbed()
Dim olMsg As MailItem
    On Error Resume Next
    Select Case Outlook.Application.ActiveWindow.Class
        Case olInspector
            Set olMsg = ActiveInspector.currentItem
        Case olExplorer
            Set olMsg = Application.ActiveExplorer.Selection.Item(1)
    End Select
    CheckScrubbed olMsg
lbl_Exit:
    Exit Sub
End Sub

Sub CheckScrubbed(olItem As MailItem)
'Graham Mayor - https://www.gmayor.com - Last updated - 03 Feb 2021
Const strFind As String = "Total Scrubbed Deferred: "
Dim olInsp As Inspector
Dim wdDoc As Object
Dim oRng As Object
Dim sText As String
Dim sMsg As String
Dim i As Integer
Dim oCol As Collection
    With olItem
        Set oCol = New Collection
        Set olInsp = .GetInspector
        Set wdDoc = olInsp.WordEditor
        Set oRng = wdDoc.Range
        With oRng.Find
            Do While .Execute(findText:=strFind & "[0-9]{1,}", MatchWildcards:=True)
                sText = Replace(oRng.Text, strFind, "")
                Select Case True
                    Case CInt(sText) = 0
                        olItem.UnRead = False
                    Case CInt(sText) > 0
                        On Error Resume Next
                        oCol.Add oRng.Text, oRng.Text
                End Select
                .collapse 0
            Loop
            If oCol.Count > 0 Then
                olItem.UnRead = True
                For i = 1 To oCol.Count
                    If i = 1 Then sMsg = oCol(i)
                    If i > 1 Then sMsg = sMsg & vbCr & oCol(i)
                Next i
                MsgBox sMsg, vbExclamation
            End If
        End With
    End With
lbl_Exit:
    Set olInsp = Nothing
    Set wdDoc = Nothing
    Set oRng = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Filter Messages Based on Phrase with Number in Content How to modify code for Auto filter based on two criteria ... LearnerExcel Excel Programming 13 02-14-2018 08:20 PM
Filter Messages Based on Phrase with Number in Content count a number of cells based on the beginning of a order number Kubi Excel 2 08-06-2017 08:54 PM
Filter Messages Based on Phrase with Number in Content Filter Mail Merge based on a list of filter criteria AusSteelMan Mail Merge 2 05-09-2016 03:35 PM
Filter Messages Based on Phrase with Number in Content Creating a plain text content control for every instance of a word or phrase RobsterCraw Word VBA 16 11-20-2012 03:25 PM
Filter Messages Based on Phrase with Number in Content Is there a way to print based on a particular filter? Jamal NUMAN Excel 4 03-20-2012 11:32 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:52 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft