简体   繁体   English

使用 excel vba 在嵌套视图中发送 Outlook 电子邮件

[英]send outlook email in nested view using excel vba

I have a code that send two email reminder to user.我有一个代码可以向用户发送两封电子邮件提醒。 The code attached below worked perfectly.下面附上的代码工作得很好。 My problem is that, I want the second reminder to be nested from the first reminder.我的问题是,我希望第二个提醒嵌套在第一个提醒中。

'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

the first reminder is nested on top of parent email, but for second reminder, instead of nested on top of first reminder and parent email, it was send as a separate mail nested on top of parent email.第一个提醒嵌套在父电子邮件之上,但对于第二个提醒,它不是嵌套在第一个提醒和父电子邮件之上,而是作为嵌套在父电子邮件之上的单独邮件发送。 how can i solve this??我该如何解决这个问题??

EDIT Example:编辑示例:

1.parent email entry ID AABJ23 1.父电子邮件条目ID AABJ23

2.first reminder will reply to parent email by setting the entryID to AABJ23 then I will get a new entry ID for the first reminder after i sent the email, ABBJ54 2.第一次提醒将通过将entryID设置为AABJ23来回复父电子邮件,然后我将在发送电子邮件后为第一次提醒获得新的条目ID,ABBJ54

3.second reminder will reply to first reminder email by setting the entry ID to ABBJ54 3.第二次提醒将通过将条目ID设置为ABBJ54来回复第一次提醒电子邮件

You are using the two different entryIDs to retrieve convo.GetRootItems(1) which is the originating item.您正在使用两个不同的 entryID 来检索作为原始项目的convo.GetRootItems(1)

The entryIDs already identify the mail you want to reply to. 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

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

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