'Delete response to meeting invite

I have the below code to permanently delete mail from the inbox.

However, when responses to a meeting invite, to say the person has accepted the meeting do not delete.

When I click on that mail and run this code it does not delete?

Sub PermDelete(Item As Outlook.MailItem)
    ' First set a property to find it again later
    Item.UserProperties.Add "Deleted", olText
    Item.Save
    Item.Delete
    
    'Now go through the deleted folder, search for the property and delete item
    Dim objDeletedFolder As Outlook.Folder
    Dim objItem As Object
    Dim objProperty As Variant
    
    Set objDeletedFolder = Application.GetNamespace("MAPI"). _
      GetDefaultFolder(olFolderDeletedItems)
    For Each objItem In objDeletedFolder.items
        Set objProperty = objItem.UserProperties.Find("Deleted")
        If TypeName(objProperty) <> "Nothing" Then
            objItem.Delete
        End If
    Next
    
End Sub


Solution 1:[1]

In the code your function accepts an instance of the MailItem class only. But an Outlook folder may contain different types of items - appointments, documents, notes and etc. To differentiate them at runtime you can use the following construction:

Dim obj As Object

If TypeName(obj) = "MailItem" Then
  ' your code for mail items here
End If

So, you need to declare the function in the following way (if you don't need to do separate actions for different kind of items):

Sub PermDelete(Item As Object)
' First set a property to find it again later
Item.UserProperties.Add "Deleted", olText
Item.Save
Item.Delete

'Now go through the deleted folder, search for the property and delete item
Dim objDeletedFolder As Outlook.Folder
Dim objItem As Object
Dim objProperty As Variant

Set objDeletedFolder = Application.GetNamespace("MAPI"). _
  GetDefaultFolder(olFolderDeletedItems)
For Each objItem In objDeletedFolder.items
    Set objProperty = objItem.UserProperties.Find("Deleted")
    If TypeName(objProperty) <> "Nothing" Then
        objItem.Delete
    End If
Next

End Sub

Solution 2:[2]

Set Item to a generic Object

Example on selected item

Option Explicit
Public Sub Example()
    Dim obj As Object
    
    Set obj = ActiveExplorer.Selection.Item(1)
        obj.Delete

End Sub

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eugene Astafiev
Solution 2