Processing incoming emails

J

John

Hi

Outlook 2003 Add-In.

How can I check the subject line of each incoming email and if a particular
string is found display an outlook alert with a link to the particular
email?

Thanks

Regards
 
Joined
Apr 14, 2008
Messages
3
Reaction score
0
Testing Subject Line in Outlook using VBA

This code works in Access, and will probably work in Outlook to look at the subject line in an email:

Dim olMAPI As Object 'Outlook.Application
Dim InItem As Object 'Outlook.MAPIFolder
Dim MItem As Object 'Outlook.MailItem

Set olMAPI = GetObject("", "Outlook.Application").GetNamespace("MAPI")
Set InItem = olMAPI.Folders("Mailbox - NameHere").Folders("Inbox")

i = 0

If InItem.Items.Count = 0 Then
Msgbox "No email in Inbox folder. . ."
DoEvents
Exit Sub
End If

Count = InItem.Items.Count

For i = Count To 1 Step -1
Set MItem = InItem.Items.Item(i)
If MItem.UnRead = True Then
mySub = MItem.Subject
If InStr(mySub, "Whatever words you're looking for here") > 0 Then
'do something here
End If
End If
Next

 
Joined
Apr 14, 2008
Messages
3
Reaction score
0
Even Better

The following will allow you to see the dot notation (early binding)
############################################

Sub TestSubjectLine()
Dim olmapi As New Outlook.Application
Dim initem As Outlook.MAPIFolder
Dim mitem As Outlook.MailItem
Set initem = olmapi.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)

If initem.Items.Count = 0 Then
MsgBox "No email in Inbox folder. . ."
Exit Sub
End If

Count = initem.Items.Count
For i = Count To 1 Step -1
Set mitem = initem.Items.Item(i)
If mitem.UnRead = True Then
mySub = mitem.Subject
If InStr(mySub, "Whatever words you're looking for here") > 0 Then
'do something here
End If
End If
Next

Set olmapi = Nothing
Set initem = Nothing
Set mitem = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top