Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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,137
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 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
 

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:41 PM.


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