Solved

Outlook VBA mail Type

Posted on 2007-03-28
4
612 Views
Last Modified: 2009-07-29
Hello,

I need to validate using VBA in outlook the type of mail coming in. As Mails are fine but read receipts are creating runtime error 13 type mismatch. I have tried declaring the mail item as type Outlook.Reportitem with no luck

Sub moveReceipt()

    Dim fdrContacts As Outlook.MAPIFolder
  Dim objContactItem As Outlook.ReportItem
   

  'Create an instance of the Contacts folder and destination folder
  Set fdrContacts = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
  Set fdrDest = fdrContacts.Folders("AutoTicket Backup")
 
 
 

      For Each objContactItem In fdrContacts.Items
 
       
        If objContactItem.Class = olReport Then
            objContactItem.Move (fdrDest)
       
       End If
           
       
       
  Next
   
       
   

End Sub
0
Comment
Question by:Cyart
  • 2
  • 2
4 Comments
 
LVL 35

Expert Comment

by:mvidas
ID: 18807946
Hi Cyart,

Dimension objContactItem as an Object, then when iterating through the items of a mapifolder, use TypeName to get the type of object (so you won't get the type mismatch error)

Dim objContactItem As Object
'...
      For Each objContactItem In fdrContacts.Items
        If TypeName(objContactItem) = "ReportItem" Then
            objContactItem.Move fdrDest
       End If


Matt
0
 

Author Comment

by:Cyart
ID: 18810476
Matt,

Thanks for the quick response, Much appreciated. Ill give it a whirl this evening
0
 
LVL 35

Accepted Solution

by:
mvidas earned 500 total points
ID: 18810564
Take your time, and let me know if you need anything else!
Matt
0
 

Author Comment

by:Cyart
ID: 18810590
cheers

Paul
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Read this checklist to learn more about the 15 things you should never include in an email signature.
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

776 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