Solved

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

Posted on 2003-12-10
1
1,546 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IntelliJ and Eclipse Neon 2 installations 4 65
Eclipse integration with Github giving error 3 51
Notepad++ Question 11 25
msiexec won't run 4 22
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
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 …

737 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