繁体   English   中英

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

[英]Excel vba code to read outlook email from inbox from bottom

借助下面的编码,我能够从Outlook收件箱中检索数据并在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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM