Link to home
Start Free TrialLog in
Avatar of rsburge
rsburgeFlag for United States of America

asked on

Search for Email Subject String

Hello - This code is working perfectly, but I have run into a situation where I need to search for specific text in the subject.  I have not been able to figure out how to fit that into this existing code.  Can you please help me update this code to search for a text string.

I need to find "EverBank" within the subject text.
Dim olApp, objFolder, objNameSpace
    Dim objItems, objMess
    Dim strFilter As String
    Dim Regex As Object, regm As Object, IE As Object
    Dim ieLink, i As Long
    strFilter = "[subject] = ""EverBank Rates"""
 
 
    Set olApp = CreateObject("Outlook.Application")
    Set objNameSpace = olApp.GetNamespace("MAPI")
    Set objFolder = objNameSpace.GetDefaultFolder(6)
    objFolder.Items.Sort "[Received]", False
    Set objItems = objFolder.Items
    objItems.Sort "[Received]", True
    Set objMess = objItems.Find(strFilter)
 
    If objMess Is Nothing Then
        MsgBox "No email found!", vbCritical
        Exit Sub
    End If
 
    Set Regex = CreateObject("vbscript.regexp")
    Regex.Pattern = "((file?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*.pdf)"
    Regex.Global = True
    If Regex.test(objMess.body) Then
        Set regm = Regex.Execute(objMess.body)
       Forms("frmPricingLoadExternal")!txtFileLoc.Value = Right$(regm(0), Len(regm(0)) - InStr(regm(0), "*"))  '& "?download=yes&cpw="
    End If
    Set olApp = Nothing
    Set Regex = Nothing

Open in new window

Avatar of Dave
Dave
Flag of Australia image

Hi again,
So 'EverBank Rates' is only part of the Subject?
As the current code will find 'EverBank Rates' if it is the full subject
Cheers
Dave
Avatar of rsburge

ASKER

Hi Dave.  Thank you for looking at this question.  Yes, EverBank Rates is only part of the subject and it can be anywhere in the subject (for some reason it is never in the same place).  Some examples are... EverBank Rates for 04072009, Today's EverBank Rates, Your EverBank Rates, Current Pricing - EverBank Rates, Wholesale EverBank Rates for 04/03/09, and tomorrow it might be different again.  :)
ASKER CERTIFIED SOLUTION
Avatar of Dave
Dave
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rsburge

ASKER

Thank you Dave!  This is awesome.  I had to make one minor adjustment...  I changed the following

from
    Set oSrh = Application.AdvancedSearch("Inbox", strF)

to
    Set oSrh = olApp.AdvancedSearch("Inbox", strF)
Avatar of rsburge

ASKER

Thanks again!  I really appreciate all of your help!  Renee
thx for the grade Renee :)
Good pick up on the Application naming
Cheers
Dave
Avatar of rsburge

ASKER

You're welcome; well earned as always.

While I still have a million questions, I am learning.  :)

Have a wonderful day!

Renee