Excel VBA代码从底部从收件箱中读取Outlook电子邮件



在以下编码的帮助下,我可以从Outlook Inbox检索数据,并在Excel中更新。问题在于,我无法更新最新的响应,因为宏读取第一次更新基础。如果我昨天得到ABC的回复,并从今天的ABC收到最新回复,那么宏正在更新昨天的响应。我们如何更改代码,以便宏应从文件夹底部读取电子邮件,并更新被拉的数据。

简而言之,我想更新记录中的最新响应。

Dim outlookApp As Outlook.Application, oOutlook As Object
Dim oInbox As Outlook.Folder, oMail As Outlook.MailItem
Dim strAddress As String, strEntryId As String, getSmtpMailAddress As String
Dim objAddressentry As Outlook.AddressEntry, objExchangeUser As Outlook.ExchangeUser
Dim objReply As Outlook.MailItem, objRecipient As Outlook.Recipient
Set outlookApp = New Outlook.Application
Set oOutlook = outlookApp.GetNamespace("MAPI")
Set oInbox = oOutlook.GetDefaultFolder(olFolderInbox)
For Each oMail In oInbox.Items
    If oMail.SenderEmailType = "SMTP" Then
        strAddress = oMail.SenderEmailAddress
    Else
        Set objReply = oMail.Reply()
        Set objRecipient = objReply.Recipients.Item(1)
        strEntryId = objRecipient.EntryID
        objReply.Close OlInspectorClose.olDiscard
        strEntryId = objRecipient.EntryID
        Set objAddressentry = oOutlook.GetAddressEntryFromID(strEntryId)
        Set objExchangeUser = objAddressentry.GetExchangeUser()
        strAddress = objExchangeUser.PrimarySmtpAddress()
    End If
    getSmtpMailAddress = strAddress
    body = oMail.body

向后循环:

    For i = oInbox.Count To 1 Step -1
        If TypeName(oInbox.item(i)) = "MailItem" Then
            Set oMail = oInbox.item(i)
            'Do stuff here
            Set oMail = Nothing
        End If
    Next i

最新更新