M
MikeC
Michael,
Try this. I just tested it and verified that it works.
Dim objOutlook As Outlook.Application
Dim nms As Outlook.NameSpace
Dim fld As Outlook.MAPIFolder
Dim itms As Outlook.Items
Dim itm As Outlook.MailItem
Dim i As Integer
Dim strProfile As String
Dim strPwd As String
strProfile = "Your Outlook Profile Name" 'Not user ID
strPwd = "Your Password"
Set objOutlook = CreateObject("Outlook.Application")
Set nms = objOutlook.GetNamespace("MAPI")
'Log into email account.
nms.Logon strProfile, strPwd, False, True
'Initialize the Outlook items collection.
Set itms = nms.Session.GetDefaultFolder
(olFolderInbox).Items
'IMPORTANT: A count down loop is *required* for
processing each item in a
'collection. Otherwise, in a "For Each x in y" loop,
the counter skips every
'other item!!! Yes, it's hard to believe, but true.
'Check each item in the "InBox".
For i = itms.Count To 1 Step -1
If itms(i).Class = olMail Then
If itms(i).Subject = "Your Subject" Then
'Do something like display a message.
MsgBox itms(i).Subject
Else
'Do something else.
End If
End If
Next i
Try this. I just tested it and verified that it works.
Dim objOutlook As Outlook.Application
Dim nms As Outlook.NameSpace
Dim fld As Outlook.MAPIFolder
Dim itms As Outlook.Items
Dim itm As Outlook.MailItem
Dim i As Integer
Dim strProfile As String
Dim strPwd As String
strProfile = "Your Outlook Profile Name" 'Not user ID
strPwd = "Your Password"
Set objOutlook = CreateObject("Outlook.Application")
Set nms = objOutlook.GetNamespace("MAPI")
'Log into email account.
nms.Logon strProfile, strPwd, False, True
'Initialize the Outlook items collection.
Set itms = nms.Session.GetDefaultFolder
(olFolderInbox).Items
'IMPORTANT: A count down loop is *required* for
processing each item in a
'collection. Otherwise, in a "For Each x in y" loop,
the counter skips every
'other item!!! Yes, it's hard to believe, but true.
'Check each item in the "InBox".
For i = itms.Count To 1 Step -1
If itms(i).Class = olMail Then
If itms(i).Subject = "Your Subject" Then
'Do something like display a message.
MsgBox itms(i).Subject
Else
'Do something else.
End If
End If
Next i