I have a VBA code In Microsoft Outlook to automatically mark any email has been added (manually or automatically) to folder (Deleted Items) as (Read).
This code is found in (ThisOutlookSession).
Private Sub DeletedFolder_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
Item.UnRead = False
End If
End Sub
On the same time there is a rule on outlook to move some emails to folder (Deleted Items) if the sender is someone e.g. [email protected],
that rule was created manually through outlook interface.
My (VBA code) and my (Outlook Rule) works simultaneously correctly till now.
But, There is a problem has raised if the Sender of an email has issued a Recall request to his message which now exists on my folder (Deleted Items) and marked as (Read).
Then a new message has been added to my folder (Deleted Items) , and when my code tries to mark it as Read
, then I have got:
(Run-time error ‘430’: Class does not support Automation or does not
support expected interface)
at this line of code Item.UnRead = False
Note 1-: you can reproduce the above error by adding the above code and manually create a rule on outlook to move messages from someone e.g. (your own email address) to folder (Deleted Items).
Then send an email for you and then go to folder (Sent Items) and open the message you have just sent and from (Actions) proceed to Recall that message.
Note 2-: I can manually mark (Recall request message) as Read
without any error, So there must be way to do the same thing through using VBA (I think).
By using the below code, I found (Recall request message) has type of: MailItem
and MessageClass: IPM.Outlook.Recall
Private Sub DeletedFolder_ItemAdd(ByVal Item As Object)
On Error GoTo ErrorHandler
' Check if the item is a MailItem and does not have a MessageClass for a recall
If TypeOf Item Is Outlook.MailItem And Item.MessageClass = "IPM.Note" Then
Dim mail As Outlook.MailItem
Set mail = Item
' Mark the MailItem as read
mail.UnRead = False
Else
' Log the item type and message class for further investigation
Debug.Print "Item Type: " & TypeName(Item) & " - MessageClass: " & Item.MessageClass
End If
Exit Sub
ErrorHandler:
Debug.Print "Error: " & Err.Number & " - " & Err.Description
Resume Next
End Sub
I have tried all the below codes. But the problem still persists.
Private Sub DeletedFolder_ItemAdd(ByVal Item As Object)
If TypeName(Item) = "MailItem" Then
' If the item is a MailItem, mark it as read
Dim mail As Outlook.MailItem
Set mail = Item
mail.UnRead = False
End If
End Sub
Private Sub DeletedFolder_ItemAdd(ByVal Item As Object)
On Error GoTo ErrorHandler
If TypeName(Item) = "MailItem" Then
' If the item is a MailItem, mark it as read
Dim mail As Outlook.MailItem
Set mail = Item
mail.UnRead = False
Else
' Log the item type for further investigation
Debug.Print "Item type: " & TypeName(Item)
End If
Exit Sub
ErrorHandler:
Debug.Print "Error: " & Err.Number & " - " & Err.Description
' Optionally, you can add more logging or error-handling logic here
Resume Next
End Sub
Private Sub DeletedFolder_ItemAdd(ByVal Item As Object)
On Error GoTo ErrorHandler
' Use late binding to interact with the Item
If TypeName(Item) = "MailItem" Then
Dim mail As Object
Set mail = Item
' Attempt to mark as read
mail.UnRead = False
End If
Exit Sub
ErrorHandler:
Debug.Print "Error: " & Err.Number & " - " & Err.Description
Resume Next
End Sub
Private Sub DeletedFolder_ItemAdd(ByVal Item As Object)
On Error GoTo ErrorHandler
' Check if the item is a MailItem by inspecting its Class property
If Item.Class = olMail Then
' It's a MailItem, mark it as read
Item.UnRead = False
Else
' Log the item's class for further inspection
Debug.Print "Item Class: " & Item.Class
End If
Exit Sub
ErrorHandler:
Debug.Print "Error: " & Err.Number & " - " & Err.Description
Resume Next
End Sub