A little variation on this theme. The message that you want to check will be saved to a certain directory in a certain format. The batfile you'll need will be attached to this message. You can choose to modify the file before running it to see the commands that I've used for checking a msg file in a directory. The code must be placed in the ThisOutlookSession under Application_NewMailEx. The directory must exists (I've used C:\Data)
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
'*** ODS JPM VD Loaded - VD_ALL_D2_20090223_N.csv***
'the mailitem
Dim myItem As Outlook.MailItem
'loop through mailitems
Dim myloop As Long
'the path to save to
Const mypath As String = "C:\Data\ODS_JPM_VD_Loaded_-_"
'the inboxfolder
Dim myfolder As Outlook.MAPIFolder
Set myfolder = Application.Session.GetDefaultFolder(olFolderInbox)
'loop through all the mailitems in inbox
For myloop = 1 To myfolder.Items.Count
'if it's a mailitem do something
If myfolder.Items.Item(myloop).Class = olMail Then
'declare myItem as the mailitem we are going to handle
Set myItem = myfolder.Items.Item(myloop)
'we only want to look at the unread items
If myItem.UnRead = True Then
'if subject equals the string we want
If Left(myItem.Subject, 34) = "*** ODS JPM VD Loaded - VD_ALL_D2_" Then
myItem.SaveAs mypath & Split(myItem.Subject, "_")(3) & ".msg", olMSG
myItem.UnRead = False
End If
End If
End If
Next myloop
End Sub
Charlize