我正在尝试在Outlook中开发一个宏以答复原始电子邮件发件人,并在CC中保留和答复原始电子邮件中CC中的所有电子邮件。 到目前为止,我有这个:
COUNT
这很好。但是,在CC中,我经常会有一些联系方式(例如:John Doe),我想在回复电子邮件时删除。
所以我想做的是保留除John Doe(在CC中)以外的所有电子邮件。 我该如何完成?
编辑:另外,当我使用它来回复电子邮件时,它将在“收件人”和“抄送”中重复该电子邮件地址。这是因为我已经在“模板”的“收件人”中定义了电子邮件,可以说这是在“收件人”和“ CC”中重复“我的老板”。如何将其从“ CC”中删除?
答案 0 :(得分:1)
这应该有效:
Sub estimate()
Dim origEmail As MailItem
Dim replyEmail As MailItem
Dim s() As String
Dim add As String
Dim i As Integer
Set origEmail = Application.ActiveWindow.Selection.Item(1)
Set replyEmail = Application.CreateItemFromTemplate("C:\Utils\Outlook_Templates\Estimate.oft")
s = Split(origEmail.CC & ";" & replyEmail.CC, ";")
For i = LBound(s) To UBound(s)
If InStr(1, s(i), "John Doe") = 0 Then
add = add & ";" & s(i)
End If
Next
replyEmail.HTMLBody = replyEmail.HTMLBody & origEmail.Reply.HTMLBody
replyEmail.Subject = "RE: " + origEmail.Subject
replyEmail.To = origEmail.Sender
replyEmail.CC = add
replyEmail.Display
End Sub
答案 1 :(得分:0)
实际上,根据Official Reference,您无意直接修改.CC
属性:
此属性仅包含显示名称。 Recipients集合应用于修改抄送收件人。
那么正确的方法是:
Dim i as Long
' If the address could occur multiple times, start at the end & work backwards
For i = replyEmail.Recipients.Count To 1 Step -1
If LCase(replyEmail.Recipients(i).Name) = LCase("John Doe") Then
replyEmail.Recipients.Remove(i)
End If
Next
replyEmail.Display
答案 2 :(得分:0)
首先,我建议您使用MailItem
类的Reply方法,而不是手动设置每个属性,该方法从原始信息。然后,您可以根据需要设置属性。
第二,如果需要设置收件人(更改,添加或删除),我建议处理Recipients
集合。 MailItem
类的相应属性返回一个Recipients集合,该集合代表Outlook项目的所有收件人。
最后,您可能会发现How To: Fill TO,CC and BCC fields in Outlook programmatically文章很有帮助。