Cyart
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").Get DefaultFol der(olFold erInbox)
Set fdrDest = fdrContacts.Folders("AutoT icket Backup")
For Each objContactItem In fdrContacts.Items
If objContactItem.Class = olReport Then
objContactItem.Move (fdrDest)
End If
Next
End Sub
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("
Set fdrDest = fdrContacts.Folders("AutoT
For Each objContactItem In fdrContacts.Items
If objContactItem.Class = olReport Then
objContactItem.Move (fdrDest)
End If
Next
End Sub
ASKER
Matt,
Thanks for the quick response, Much appreciated. Ill give it a whirl this evening
Thanks for the quick response, Much appreciated. Ill give it a whirl this evening
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
cheers
Paul
Paul
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