Solved

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

Posted on 2003-12-10
1
1,519 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
powerN  challenge 3 56
groovy example issue 10 89
SUM 2 INTEGER ARRAYS INTO 1 10 93
Turning python script into an applet 12 101
RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
This is an explanation of a simple data model to help parse a JSON feed
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

914 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now