我是VBA的新手。我想询问如何触发已回复的电子邮件。
场景:我有如下编码,如果C栏中有“是”,则会将电子邮件发送给收件人(B栏)。
For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "C").Value) = "yes" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = cell.Value
.Subject = "Reminder"
.Body = "Dear " & Cells(cell.Row, "A").Value _
& vbNewLine & vbNewLine & _
"Please contact us to discuss bringing " & _
"your account up to date"
'You can add files also like this
'.Attachments.Add ("C:\test.txt")
.Send 'Or use Display
End With
问题:如果收件人回复了我之前发送的电子邮件,我该如何触发?我想在E列上自动触发我的excel文件,因为备注收件人已回复我的电子邮件。例如,“回复/没有回复”。
非常感谢任何帮助,因为我是VBA的新手。 谢谢。
答案 0 :(得分:0)
假设您使用的是Microsoft Outlook和Exchange Server。
有3个扩展MAPI属性可处理回复/转发的消息状态:
PR_ICON_INDEX(0x10800003)
PR_LAST_VERB_EXECUTED(0x10810003)
PR_LAST_VERB_EXECUTION_TIME(0x10820040)
此MSDN文章https://msdn.microsoft.com/en-us/library/bb176395(office.12).aspx提供了显示如何使用这些MAPI属性的代码:
Sub DemoPropertyAccessorGetProperty()
Dim PropName, Header As String
Dim oMail As Object
Dim oPA As Outlook.PropertyAccessor
'Get first item in the inbox
Set oMail = _
Application.Session.GetDefaultFolder(olFolderInbox).Items(1)
'PR_TRANSPORT_MESSAGE_HEADERS
PropName = "http://schemas.microsoft.com/mapi/proptag/0x007D001E"
'Obtain an instance of PropertyAccessor class
Set oPA = oMail.PropertyAccessor
'Call GetProperty
Header = oPA.GetProperty(PropName)
Debug.Print (Header)
End Sub
你会想要在上面的代码中替换'PR_TRANSPORT_MESSAGE_HEADERS,即 0x007D001E ,我猜你想要的不仅仅是第一个邮件......