首页 > 解决方案 > 无法将电子邮件移动到另一个文件夹错误 438 对象不支持此属性或方法

问题描述

我正在尝试将具有特定主题的电子邮件标记为已读并将其移动到另一个文件夹。错误就行了.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

标签: excelvbaoutlook

解决方案


用这个 :

Dim outlookmail As Outlook.MailItem
    For Each outlookmail In Folder.Items
        If TypeOf outlookmail Is MailItem Then
        If outlookmail.Subject = "The following building has been permanently retired" Then
        With outlookmail
            .UnRead = False
            .Move RetiredFolder
        End With
        End If
        End If
    Next outlookmail

推荐阅读