Hi Domenic,
Yes I did populate the Outlook Library in addition despite the screen shot not displaying this so I think we are ok on that note?
Am I right in assuming no alterations need to be made to the code by myself as long as your initial 3 conditions/assumptions are adhered to?
This is the code I've just copied from the compiler:
Option Explicit
Sub MoveEmailsToDeletedItemsFolder()
On Error GoTo errorHandler
Dim sourceWorksheet As Worksheet
Set sourceWorksheet = ThisWorkbook.Worksheets("Sheet1") 'change the sheet name accordingly
Dim EmailsToDelete As Variant
Dim lastRow As Long
With sourceWorksheet
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
EmailsToDelete = .Range("A1:A" & lastRow).Value
End With
Dim olApp As Outlook.Application
Set olApp = New Outlook.Application
Dim olNS As Outlook.Namespace
Set olNS = Outlook.GetNamespace("MAPI")
Dim olInbox As Outlook.Folder
Set olInbox = olNS.GetDefaultFolder(olFolderInbox)
Dim olDeletedItemsFolder As Outlook.Folder
Set olDeletedItemsFolder = olNS.GetDefaultFolder(olFolderDeletedItems)
Dim olItem As Variant
Dim olMailItem As Outlook.MailItem
Dim deletedEmailCount As Long
Dim i As Long
deletedEmailCount = 0
With olInbox
For i = .Items.Count To 1 Step -1
If .Items(i).Class = olMail Then
Set olMailItem = .Items(i)
If Not IsError(Application.Match(olMailItem.SenderEmailAddress, EmailsToDelete, 0)) Then
olMailItem.Move olDeletedItemsFolder
deletedEmailCount = deletedEmailCount + 1
End If
End If
Next i
End With
MsgBox "Emails moved to deleted items folder: " & deletedEmailCount, vbInformation
exitHandler:
Set olApp = Nothing
Set olNS = Nothing
Set olInbox = Nothing
Set olDeletedItemsFolder = Nothing
Set olMailItem = Nothing
Exit Sub
errorHandler:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "Error"
Resume exitHandler
End Sub
Thanks again,
Tom