Я пытаюсь пометить письмо с указанным c субъектом как прочитанное и переместить его в другую папку. Ошибка на линии .UnRead = False
.
Эта строка вызывает ошибку 438. Я пробовал разные комбинации myitem
с одинаковым результатом.
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