excel - 使用 excel vba 在嵌套视图中发送 Outlook 电子邮件
问题描述
我有一个向用户发送两封电子邮件提醒的代码。下面附加的代码运行良好。我的问题是,我希望第二个提醒嵌套在第一个提醒中。
'create session
Dim OutApp As Object
Dim newMail As Object
Dim Emailto, sendfrom As String
'create reply
Dim convo As Conversation
Dim convoItem
Dim entry As String
For J = ws.Cells(5, "C").Value To ws.Cells(6, "C").Value
'get value from combo box
If combovalue = "First Reminder" Then
'MsgBox combovalue
'set a reply
Set OutApp = CreateObject("Outlook.Application")
Set OutNS = OutApp.GetNamespace("MAPI")
entry = ws.Cells(J, "G")
Set mail = OutNS.GetItemFromID(entry) 'get handle on mail item
Set convo = mail.GetConversation 'get handle on existing conversation
Set convoItem = convo.GetRootItems(1) 'get convo root item
Set newMail = convoItem.Reply 'new email as reply to convo
Emailto = ws.Cells(J, "D").Value
sendfrom = "email"
On Error Resume Next
With newMail
.SendUsingAccount = sendfrom
.To = Emailto
.Subject = "Test"
.VotingOptions = "Acknowledge;"
.BodyFormat = olFormatHTML
.HTMLBody = "Body here"
.Send 'or use .Display to open Outlook's new message window before sending
ws.Cells(J, "T").Value = Date
End With
On Error GoTo 0
Set OutApp = Nothing
Set newMail = Nothing
End If
If combovalue = "Second Reminder" Then
'MsgBox ("Correct")
Set OutApp = CreateObject("Outlook.Application")
Set OutNS = OutApp.GetNamespace("MAPI")
entry = ws.Cells(J, "Z")
Set mail = OutNS.GetItemFromID(entry) 'get handle on mail item
Set convo = mail.GetConversation 'get handle on existing conversation
Set convoItem = convo.GetRootItems(1) 'get convo root item
Set newMail = convoItem.Reply 'new email as reply to convo
Emailto = ws.Cells(J, "D").Value
sendfrom = "email"
On Error Resume Next
With newMail
.SendUsingAccount = sendfrom
.To = Emailto
.BCC = ""
.Subject = "Test"
.VotingOptions = "Acknowledge;"
.BodyFormat = olFormatHTML
.HTMLBody = "Body here"
.Send 'or use .Display to open Outlook's new message window before sending
ws.Cells(J, "U").Value = Date
End With
On Error GoTo 0
Set OutApp = Nothing
Set newMail = Nothing
End If
Next J
第一个提醒嵌套在父电子邮件之上,但对于第二个提醒,它不是嵌套在第一个提醒和父电子邮件之上,而是作为嵌套在父电子邮件之上的单独邮件发送。我该如何解决这个问题?
编辑 示例:
1.parent email entry ID AABJ23
2.第一个提醒将通过将entryID设置为AABJ23来回复父电子邮件,然后我将在我发送电子邮件后为第一个提醒获得一个新的条目ID,ABBJ54
3.第二次提醒将通过设置条目ID为ABBJ54回复第一次提醒电子邮件
解决方案
您正在使用两个不同的 entryID 来检索convo.GetRootItems(1)
哪个是原始项目。
entryID 已经标识了您要回复的邮件。
If comboValue = "First Reminder" Then
entry = ws.Cells(j, "G") ' entryID of the parent mail
Set Mail = OutNS.GetItemFromID(entry) 'get handle on parent mail
Set newMail = Mail.reply 'new email as reply to parent mail
End If
If comboValue = "Second Reminder" Then
entry = ws.Cells(j, "Z") ' entryID of first reminder
Set Mail = OutNS.GetItemFromID(entry) 'get handle on first reminder item
Set newMail = Mail.reply 'new email as reply to first reminder
End If
推荐阅读
- r - 检查一个因子中的所有因子是否都是唯一的,如果是,则返回该因子。如果不是,则返回第三个值。R
- amazon-web-services - AWS Connect:将自定义 CCP 放在首位
- docker - 在 Windows 上使用 Postgres 和 Docker 的卷的默认位置
- javascript - Redux-form 异步验证,避免使用“throw”
- node.js - Houndify Speech to Text 将 SpokenRespons 留空
- html - 网页上的 CSS / HTML 溢出问题
- acumatica - 重定向操作中的数据视图搜索不一致?
- gradle - IntelliJ IDEA(2020.2):Gradle:锁定文件:repository/caches/journal-1/journal-1.lock
- vue.js - 页面刷新后 Axios 拦截器不起作用(Vue.js)
- git - 如果将 Jenkins 管道作为代码提交(用于 SCM 设置的管道脚本),如何停止构建触发器