vba excel- outlook-对于每个 - 返回邮件= Nothing -Orror Mngt



我在Excel上做了一个小宏,旨在在Outlook上寻找特定主题和特定收到的时间的邮件。除了与我的同事之一的Oulook收件箱外,几乎所有人都可以很好地工作。

我写的代码:

For Each olMail In oDefaultFolder.Items
    If olMail.Subject = "DDJ of " & date_target Then
        MyAr = Split(olMail.Body, vbCrLf)
        For i = LBound(MyAr) To UBound(MyAr)
        Sheets("DDJ").Cells(i + 1, 1).Value = MyAr(i)
        Next i
        ddj_empty = False
        Exit For
    End If
Next olMail

我尝试了3个Outlook帐户,没有PB,但是有第四个帐户。

它返回的pb是突出显示"下一个Olmail",说Olmail = Nothing我希望我的宏继续进行搜索,并且我很难处理这个错误。

我正在寻找类似于"如果noce = nothing,则i = i 1 ..下一个i"的SMTG,但是我在Google A上找到了"继续",但我的Excel不认识继续函数吗?所以我不知道该怎么办

有建议吗?非常感谢

Outlook文件夹可以包含不同的项目类型。不同类型并不相同。例如,会议网络支持会议空间的财产。MailItems没有。

在使用olMail之前,使用VBA打字机函数检查类型是一个好主意。

' Perform action on specific item types only.
' TESTED: Outlook 2010.
Sub CheckItemType()
    Dim i As Object         ' Used to loop over items.
    Dim iType As String     ' Used to hold type of above item.
        ' Loop over all items in the inbox.
        For Each i In Outlook.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
            iType = TypeName(i)
            ' Limit actions to required types.
            If iType = "MailItem" Or iType = "MeetingItem" Then
                ' Your logic.
            End If
        Next
End Sub

最新更新