Solved

VB.Net loop though Outlook folder Need to find type of item....

Posted on 2003-12-10
1
1,528 Views
Last Modified: 2012-05-04
I have a loop that loops though each message in a Outlook folder...  Outlook 2003/ VB.Net 2003/ XP operating system.
Exchange 5.5

        Dim myOlapp As Outlook.Application
        Dim myoMsg As Outlook.MailItem
        Dim myOFolder As Outlook.MAPIFolder

        myOlapp = CreateObject("Outlook.Application")
        myoMsg = myOlapp.CreateItem(Outlook.OlItemType.olMailItem)
        myOFolder = GetFolder(sInboxMailFolder)
        for each myomsg   in myOfolder.items
            If myoMsg.Attachments.Count > 0 Then
             ....
             ......
           end if
        next message.

My probem is that sometimes there are other types of messages in there (Hidden, contacts etc).

I would like to see the type first then do something with it.

What is the best way to do this.

Thanks,

Rog
0
Comment
Question by:Rog
1 Comment
 
LVL 4

Accepted Solution

by:
bhartung earned 250 total points
ID: 9921077
You could use the MessageClass property of the Item to tell what kind it is.  Perhaps you want to just deal with mail items.  One way to restrict the list of items to those of a particular class is with the Restrict method on the Items collection.  There's probably a better way to do this, but:

Dim myOlapp As New Outlook.Application
Dim myOFolder As Outlook.MAPIFolder
Dim myoNS As Outlook.NameSpace
Dim myoItems As Outlook.Items
Dim myoMsg As Outlook.MailItem

Set myoNS = myOlapp.GetNamespace("MAPI")
Set myOFolder = myoNS.GetDefaultFolder(olFolderInbox)
       
Set myoItems = myOFolder.Items.Restrict("[Message Class]='IPM.Note'")
       
For Each myoMsg In myoItems
    If myoMsg.Attachments.Count > 0 Then
        MsgBox myoMsg.Subject & " has " & myoMsg.Attachments.Count & " attachments"
    End If
Next
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question