Link to home
Start Free TrialLog in
Avatar of Cyart
CyartFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Outlook VBA mail Type

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
Avatar of mvidas
mvidas
Flag of United States of America image

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
Avatar of Cyart

ASKER

Matt,

Thanks for the quick response, Much appreciated. Ill give it a whirl this evening
ASKER CERTIFIED SOLUTION
Avatar of mvidas
mvidas
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Cyart

ASKER

cheers

Paul