Outlook automation

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
 
M

MikeC

Michael,

I have not experienced the count down issue using a "For
Each" loop when processing collections of forms or
tables. I've seen this problem only in Outlook. It's
possible that it may be lurking somewhere else, but I
haven't seen it.
 

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