簡體   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