我希望能够选择一堆电子邮件并运行宏,并省略一个特定的域名。如何修改我的代码,以便不向特定域的人发送自动回复,例如" @ domain.com"?感谢
Option Explicit
Sub ReplywithTemplate2()
Dim Item As Outlook.MailItem
Dim oRespond As Outlook.MailItem
Dim OutPut As Integer
For Each Item In ActiveExplorer.Selection
' This sends a response back using a template
Set oRespond = Application.CreateItemFromTemplate("C:\Users\Accounting\AppData\Roaming\Microsoft\Templates\scautoreply.oft")
On Error Resume Next
With oRespond
.SentOnBehalfOfName = "Subpayables Invoices"
.Recipients.Add Item.SenderEmailAddress
.Subject = Item.Subject 'use Item.Subject to keep the original subject
' use .display for testing, change to .send once you have it working as desired
.Display
End With
Next
OutPut = MsgBox("Successfully Completed the Task.", vbInformation, "Auto Reply From Template")
Set oRespond = Nothing
End Sub
答案 0 :(得分:0)
您必须在添加收件人之前进行测试,因此请将Recipients.Add Item.SenderEmailAddress
更改为:
If InStr(1, Item.SenderEmailAddress, "domain.com") > 0 Then
'User from "@domain.com"
'Do not respond
Else
'Not a user from "@domain.com"
.Recipients.Add Item.SenderEmailAddress
End If