I am trying to mark an email with a specific subject as read and move it to another folder. The error is on the line .UnRead = False
.
This line is causing the error 438. I have tried different combinations of myitem
with the same result.
Dim OutlookApp As Outlook.Application
Dim OutlookNamespace As Namespace
Dim Folder As Outlook.MAPIFolder
Dim OutlookMail As Variant
Dim DestFolder As Outlook.MAPIFolder
Dim RetiredFolder As Outlook.MAPIFolder
Dim myItem As Object
Dim myItems As Outlook.MailItem
Application.ScreenUpdating = False
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Emails")
Set wsNS = wb.Worksheets("NS_Export")
ws.Activate
Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set Folder = OutlookNamespace.Folders("myemail").Folders("NOC Announcements New")
Set RetiredFolder = OutlookNamespace.Folders("tmyemail").Folders("Retired Buildings")
For Each OutlookMail In Folder.Items
Set myItem = Folder.Items.Find("[Subject] = 'The following building has been permanently retired'")
With myItem
.UnRead = False
.Move RetiredFolder
End With
Next OutlookMail