Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
scoresIncreasing challenge 10 57
sumHeights2  challenge 7 78
nestparen challenge 4 58
parse convert xml feed to text (python) 2 32
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 about my first experience with programming Arduino.
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 …

743 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

15 Experts available now in Live!

Get 1:1 Help Now