[英]Excel vba code to read outlook email from inbox from bottom
With the help of below coding I am able to retrieve the data from outlook inbox and update the same in excel. 借助下面的编码,我能够从Outlook收件箱中检索数据并在excel中进行更新。 The problem is that I am not able to update the latest response as macro read first come first update basis. 问题是我无法更新最新的响应,因为宏读取先到先更新。 If I get the response from abc yesterday and updated response from abc today, the macro is updating the yesterday's response. 如果我昨天收到了abc的响应,而今天又收到了abc的更新响应,则该宏将更新昨天的响应。 How can we change the code so that macro should read the emails from bottom of folder and the data that is pulled is updated. 我们如何更改代码,以便宏应从文件夹底部读取电子邮件,并提取提取的数据。
In short, I want to update the latest response in my records. 简而言之,我想更新记录中的最新回复。
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
Loop backwards: 向后循环:
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.