excel 运行时错误'438' for outlook items on [duplicate]

pbgvytdp  于 6个月前  发布在  其他
关注(0)|答案(1)|浏览(55)

此问题在此处已有答案

Treating Item As MailItem(1个答案)
Return mailitem property from item in inbox: Run time error '438': object doesn't support this property or method"(1个答案)
Returning mailitem property of item in inbox: Error 438 object doesn't support this property or method(2个答案)
19天前关闭
如何解决运行时错误'438':Object doesn't support this property或方法错误,发生在下面的vba代码的“If olMail.SenderEmailAddress =“email protected(https://stackoverflow.com/cdn-cgi/l/email-protection)“Then”行

Sub MaildenDosyaKopyala()
    Dim olApp As Object
    Dim olNamespace As Object
    Dim olFolder As Object
    Dim olMail As Object
    Dim olAttachment As Object
    Dim DesktopPath As String
    Dim FilePath As String
    Dim FileName As String
    
    ' Outlook uygulamasını başlat
    Set olApp = CreateObject("Outlook.Application")
    Set olNamespace = olApp.GetNamespace("MAPI")
    
    ' Gelen Kutusu'nu aç
    Set olFolder = olNamespace.GetDefaultFolder(6) ' 6, gelen kutusunu temsil eder. Diğer klasörler için numaraları değiştirin.
    
    ' Masaüstü yolunu al
    DesktopPath = CreateObject("WScript.Shell").SpecialFolders("Desktop")
    FileName = "aaa.xlsx"
    
    ' Gelen mailleri kontrol et
    For Each olMail In olFolder.Items
        If olMail.SenderEmailAddress = "[email protected]" Then
            For Each olAttachment In olMail.Attachments
                If olAttachment.FileName = FileName Then
                    FilePath = DesktopPath & "\" & FileName
                    olAttachment.SaveAsFile FilePath
                    Exit For
                End If
            Next olAttachment
        End If
    Next olMail
    
    Set olAttachment = Nothing
    Set olMail = Nothing
    Set olFolder = Nothing
    Set olNamespace = Nothing
    Set olApp = Nothing
End Sub

字符串
找不到任何解决办法

m2xkgtsf

m2xkgtsf1#

您的收件箱可以包含MailItem以外的项目,例如不公开SenderEmailAddress属性的ReportItemMeetingRequestItem
首先检查您是否有邮件:

If olMail.Class = 43 Then '43 is olMailItem

字符串
或者,更好的方法是,不要遍历文件夹中的所有项目(可能包含数千个项目),让消息存储来完成繁重的工作:

For Each olMail In olFolder.Items.Restrict("[SenderEmailAddress] = '[email protected]' ")

相关问题