Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-27-2015, 09:27 AM
kcm5153 kcm5153 is offline Rule: Look for this number string and only this number string Windows 8 Rule: Look for this number string and only this number string Office 2013
Novice
Rule: Look for this number string and only this number string
 
Join Date: Mar 2015
Posts: 3
kcm5153 is on a distinguished road
Default Rule: Look for this number string and only this number string

Hi,



I am looking for a solution to a rule I have created in Outlook. I am asking outlook to do a few things.

1. Look for a string of number ex. 5555
2. AND look for a phrase ex. "1 rating"

Then

3. Move to this folder ex. "1 Rating Folder"
4. AND forward this email to ex. "example@outlook.com"

I am having trouble when an email comes in with other numbers like 5555123 -- outlook sees "5555" inside this string of numbers and applies the rest of the steps.

How to I make my rule only look for "5555" by itself, no additional numbers in the front or at the end. Essentially I want to make it an exclusive rule.
Reply With Quote
  #2  
Old 03-28-2015, 01:00 AM
gmayor's Avatar
gmayor gmayor is offline Rule: Look for this number string and only this number string Windows 7 64bit Rule: Look for this number string and only this number string Office 2010 32bit
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 can do it with a script run from a rule. The following assumes the required texts are in the message body. I have included a macro to test it on a file in the inbox. Ensure that you don't have Outlook configured to send immediately while testing.

Code:
Option Explicit
Sub MoveToFolder(olMail As Outlook.MailItem)
Dim strNum As String
Dim strText As String
Dim olOutMail As Outlook.MailItem
Dim olInsp As Outlook.Inspector
Dim strFolder As String
Dim wdDoc As Object
Dim oRng As Object
Dim iCount As Long
    iCount = 0
    strNum = "<5555>"
    strText = "1 rating"
    strFolder = "1 Rating Folder" 'Folder must exist!
    With olMail
        Set olInsp = .GetInspector
        Set wdDoc = olInsp.WordEditor
        Set oRng = wdDoc.Range
        With oRng.Find
            Do While .Execute(FindText:=strNum, MatchWildCards:=True)
                iCount = iCount + 1
                Exit Do
            Loop
        End With
        Set oRng = wdDoc.Range
        With oRng.Find
            Do While .Execute(FindText:=strText, MatchWildCards:=False, MatchCase:=False)
                iCount = iCount + 1
                Exit Do
            Loop
        End With
    End With
    If iCount = 2 Then
        Set olOutMail = olMail.Forward
        With olOutMail
            .To = "example@gmayor.com"
            .sEnd
        End With
        olMail.Move Session.GetDefaultFolder(olFolderInbox).folders(strFolder)
    End If
lbl_Exit:
    Exit Sub
End Sub

Sub TestItem()
Dim olMsg As MailItem
    On Error Resume Next
    Set olMsg = ActiveExplorer.Selection.Item(1)
    MoveToFolder olMsg
lbl_Exit:
    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
  #3  
Old 03-30-2015, 01:25 PM
kcm5153 kcm5153 is offline Rule: Look for this number string and only this number string Windows 8 Rule: Look for this number string and only this number string Office 2013
Novice
Rule: Look for this number string and only this number string
 
Join Date: Mar 2015
Posts: 3
kcm5153 is on a distinguished road
Default Thank you

thank you so much for your help. One more question how do multiple rules? Can I put similar code inside the same script?

Example, I want outlook to 1. look for 5555 and 1 rating then if they are both found 1. move to folder 2. forward to jane@example.com

Outlook cannot find 5555 then I want it to look for 1111 and 1 rating and repeat additional rules 1. move to folder 2. forward to mike@example.com

is there a limit on how many of these rules I can put in place?
Reply With Quote
  #4  
Old 03-30-2015, 10:15 PM
gmayor's Avatar
gmayor gmayor is offline Rule: Look for this number string and only this number string Windows 7 64bit Rule: Look for this number string and only this number string Office 2010 32bit
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 only need the one rule. You can set the searches in the script.

You can loop through a list of numbers and apply the corresponding e-mail addresses. I assume they are all going to the same folder, if not you will need to treat the folders in the same way with a matching folder for each number.

The following is not tested, but should work.

Code:
Sub MoveToFolder(olMail As Outlook.MailItem)
Dim strText As String
Dim olOutMail As Outlook.MailItem
Dim olInsp As Outlook.Inspector
Dim wdDoc As Object
Dim oRng As Object
Dim iCount As Long
Dim vEmail As Variant
Dim vNum As Variant
Dim i As Long
Const strFolder As String = "1 Rating Folder"        'folder must exist
Const strNum As String = "<5555>|<1111>"        'separate search strings with '|'
Const strEmail As String = "jane@example.com|mike@example.com"        'Corresponding e-mail addresses to strNum

strText = "1 rating"        'Common folder
    vEmail = Split(strEmail, "|")
    vNum = Split(strNum, "|")
    
    Set olInsp = olMail.GetInspector
    Set wdDoc = olInsp.WordEditor

    For i = LBound(vNum) To UBound(vNum)
        With olMail
            iCount = 0
            Set oRng = wdDoc.Range
            With oRng.Find
                Do While .Execute(FindText:=vNum(i), MatchWildCards:=True)
                    iCount = iCount + 1
                    Exit Do
                Loop
            End With
            Set oRng = wdDoc.Range
            With oRng.Find
                Do While .Execute(FindText:=strText, MatchWildCards:=False, MatchCase:=False)
                    iCount = iCount + 1
                    Exit Do
                Loop
            End With
        End With
        If iCount = 2 Then
            Set olOutMail = olMail.Forward
            With olOutMail
                .To = vEmail(i)
                .sEnd
            End With
            olMail.Move Session.GetDefaultFolder(olFolderInbox).folders(strFolder)
        End If
    Next i
lbl_Exit:
    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

Tags
rule

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find number of coma and then add that number of rows in word using macro? PRA007 Word VBA 7 05-27-2015 10:45 PM
Rule: Look for this number string and only this number string Heading's Footnote's number is displayed in TOC. How to remove the number in TOC? Orehrepus Word 1 07-13-2014 12:51 PM
Rule: Look for this number string and only this number string How to create a table with a number of line depending a number entered by user Cellendhyll Word Tables 3 07-10-2014 05:49 AM
Rule: Look for this number string and only this number string Way to search for a string in text file, pull out everything until another string? omahadivision Excel Programming 12 11-23-2013 12:10 PM
Rule: Look for this number string and only this number string Extracting a phone number from a string that contains text and numbers. hommi16 Excel 2 06-05-2013 09:19 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:38 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