【发布时间】:2015-08-10 17:10:43
【问题描述】:
美好的一天 下面的代码根据其他列为 A 列中的每一行生成一个唯一的电子邮件 + 附件。
这意味着如果同一封电子邮件存在不止一次,他们将收到不止一封电子邮件。我想做的是检查电子邮件是否存在多行(已经排序),然后只向他们发送一封电子邮件(包含所有附件)。这可能吗?
这是我的代码:
Dim objOutlook As Outlook.Application
Dim objMail As Outlook.MailItem
Dim rngTo As Range
Dim rngSubject As Range
Dim rngBody As Range
Dim rngAttach As Range
ActiveSheet.Range("A2").Select
Do Until IsEmpty(ActiveCell)
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItemFromTemplate("C:\Desktop\EBILL\template.oft")
With objMail
.To = ActiveCell.Offset(0, 4).Value
.Subject = "Invoice For: " & " " & Month & " - " & Year
.Attachments.Add ActiveCell.Offset(0, 5).Value
ActiveCell.Offset(1, 0).Select
.Display 'Instead of .Display, you can use .Send to send the email or .Save to save a copy in the drafts folder
End With
Loop
Set objOutlook = Nothing
Set objMail = Nothing
Set rngTo = Nothing
Set rngSubject = Nothing
Set rngBody = Nothing
Set rngAttach = Nothing
【问题讨论】:
-
都是A2单元格下的邮箱吗?
-
所有电子邮件都是 vlookup 的结果,列在 (E) 列中。所以基本上我会有 5 个用户,其中 3 个是唯一的,1 个有 2 个条目。这主要用于向客户发送账单。