Solved

Outlook Application_NewMailEx event - check for string match

Posted on 2010-09-16
5
1,270 Views
Last Modified: 2012-05-10
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
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 33696554
Hi, murbro.

What version of Outlook are you using?  
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 33696569
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
 

Author Comment

by:Murray Brown
ID: 33698851
Great, thanks very much. I am using Office 2010
0
 
LVL 76

Assisted Solution

by:David Lee
David Lee earned 500 total points
ID: 33699406
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
 
LVL 76

Expert Comment

by:David Lee
ID: 33699555
You're welcome!
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question