Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1296
  • Last Modified:

Outlook Application_NewMailEx event - check for string match

Hi

I want to see if there is a string match for any email in the subject of the message using the Application_NewMailEx event. What code would I use?
0
Murray Brown
Asked:
Murray Brown
  • 4
2 Solutions
 
David LeeCommented:
Hi, murbro.

What version of Outlook are you using?  
0
 
David LeeCommented:
This is the code for doing this.  I need to know the version in order to provide specific instructions for adding it to Outlook.
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
    Dim arrEID As Variant, varEID As Variant, olkItem As Object
    arrEID = Split(EntryIDCollection, ",")
    For Each varEID In arrEID
        Set olkItem = Session.GetItemFromID(varEID)
        If olkItem.Class = olMail Then
            If olkItem.Subject = "The string to find" Then
                'Your code goes here'
            End If
        End If
    Next
    Set olkItem = Nothing
End Sub

Open in new window

0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Great, thanks very much. I am using Office 2010
0
 
David LeeCommented:
I don't have 2010 loaded yet, so I can't test with that version.  I wrote this on a box with 2007 and it works fine.  It should work in 2010 without any problem.  Because I don't have 2010 loaded I don't have a set of instructions for that version.  Here are the instructions for 2007.  Hopefully they're close.

1.  Start Outlook
2.  Click Tools > Macro > Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
5.  Edit the code as needed.  I included comment lines wherever something needs to or can change
6.  Click the diskette icon on the toolbar to save the changes
7.  Close the VB Editor
8.  Click Tools > Trust Center
9.  Click Macro Security
10. Set Macro Security to "Warnings for all macros"
11. Click OK
12. Close Outlook
13. Start Outlook.  Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run.  Say yes.
0
 
David LeeCommented:
You're welcome!
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now