Remove contacts from Outlook's Deleted Items folder

Craig__

Board Regular
Joined
Feb 16, 2010
Messages
66
From this Excel macro, I want to loop through Outlook's default Deleted Items folder and remove only the items that are Contacts.
I've worked out how to remove all items, but not just the Contact items.
I'd be grateful if someone could help me with this.

Sub Remove_Contacts_From_Deleted_Items_Folder()

Dim oApplOutlook As Object
Dim oNsOutlook As Object
Dim oDelFolder As Object
Dim oDelItems As Object
Dim i As Long
Dim lngCount As Long

On Error Resume Next
Set oApplOutlook = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then
Set oApplOutlook = CreateObject("Outlook.Application")
End If
On Error GoTo 0

Set oNsOutlook = oApplOutlook.GetNamespace("MAPI")
Set oDelFolder = oNsOutlook.GetDefaultFolder(3) ' 3 = Deleted Items folder.
Set oDelItems = oDelFolder.Items

' This removes ALL deleted items:
' c = oDelItems.Count
' For n = c To 1 Step -1
' oDelItems(n).Delete
' Next n

' But I only want to remove any "Contact" items.
' I'm not sure how, but something like this:

For Each oDelItems In oDelFolder
If oDelItems = OutlookContact Then
oDelItems.Delete
End If
Next

End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
No worries, I think I've managed to answer my own question. This seems to work ok:

For i = oDelItems.Count To 1 Step -1
If TypeName(oDelFolder.Items.Item(i)) = "ContactItem" Then
oDelItems.Item(i).Delete
End If
Next i


Thanks
 
Upvote 0

Forum statistics

Threads
1,212,938
Messages
6,110,775
Members
448,298
Latest member
carmadgar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top