PC Review Forums Newsgroups Microsoft Outlook Microsoft Outlook VBA Programming Loop through messages in inbox

Reply

Loop through messages in inbox

 
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average.
Old 30-06-2003, 05:16 PM   #1
Eric W.
Guest
 
Posts: n/a
Default Loop through messages in inbox


I am coding for the first time using the Outlook object
model. I have used VBA in Excel and Access before, so I
do have some experience. So I need to loop through the
emails in my Inbox and look for the email to have an
attachment named "email Query.xls". I'm sure there is an
easy way to do this. I am coding from within Outlook.
Any help is welcome.
  Reply With Quote
Old 01-07-2003, 12:51 AM   #2
andrei
Guest
 
Posts: n/a
Default Re: Loop through messages in inbox

I had similar problem: to look for specific items inside the Inbox.
Enumerating all items is straightforward, but VERY slow. That's what I am
using:

Dim myNS As NameSpace
Set myNS = outlookApp.GetNamespace("MAPI")

Dim inFolder As Outlook.MAPIFolder
Set inFolder = myNS.GetDefaultFolder(olFolderInbox)

Dim msg ' do not put As MailItem!!!
For Each msg In inFolder.Items
If Not TypeOf msg Is MailItem Then
If msg.UnRead = True Then ' your criteria here
....
End If
End If
Next

There are several associated problems:

1. If the item is not MailItem, the loop is terminated. I learned it the
hard way;

2. Most of the properties are "protected" - Outlook is displaying a message
box, asking, whether to go ahead. To avoid that, you have to use
Redemption, which is presenting other problems;

3. Outlook inserts the new items either at the beginning or at the end of
the list. Unfortunately, I have no idea how to find out, which method is
being used. Sorting items has no effect on that. With large Inbox, lookup
is taking quite a while. If anybody can comment on that, would be
wonderful;

4. Do not expect the following statement to be always correct:
MsgBox "Inbox should contain " & _
inFolder.Items.Count & " items, of which " & _
inFolder.UnReadItemCount & " are unread."
On one PC, it is steadily reporting approx. twice as much items, and half
of them to be unread (instead of one). My only guess is trashed Inbox. But
you can't tell that to the customer, if he don't have other Outlook
problems. Because of that, I can not use indexing to enumerate items
backwards.

Overall, I am surprised by Outlook's instability and lack of decent online
documentation. You have to guess and poke around...

Any further comments greatly appreciated.

Regards,
Andrei




"Eric W." <eric.winegarner@gtech.com> wrote in news:015501c33f2b$584b4f60
$a301280a@phx.gbl:

> I am coding for the first time using the Outlook object
> model. I have used VBA in Excel and Access before, so I
> do have some experience. So I need to loop through the
> emails in my Inbox and look for the email to have an
> attachment named "email Query.xls". I'm sure there is an
> easy way to do this. I am coding from within Outlook.
> Any help is welcome.
>


  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off