【发布时间】:2018-07-02 17:22:03
【问题描述】:
我正在尝试查看 A 列,查找所有唯一的电子邮件地址,为每个电子邮件地址创建一个 Outlook 电子邮件,并使用该电子邮件地址所在的行(也包括标题)填充该电子邮件的正文。
示例数据:
+----------------+---------------------+---------+
| Email | Application | Version |
+----------------+---------------------+---------+
| test1@test.com | Microsoft_Office_13 | v2.0 |
| test1@test.com | Putty | v3.0 |
| test1@test.com | Notepad | v5.6 |
| test2@test.com | Microsoft_Office_13 | v2.0 |
| test2@test.com | Putty | v3.0 |
| test2@test.com | Adobe_Reader | v6.4 |
| test3@test.com | Microsoft_Office_13 | v3.6 |
| test3@test.com | Paint | v6.4 |
| test3@test.com | Adobe_Reader | v6.4 |
+----------------+---------------------+---------+
这是我找到的,但它会在每次列出地址时创建一封电子邮件。它也没有任何代码显示如何将一系列细胞拉入体内。
Sub Test1()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
For Each cell In Columns("A").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "C").Value) = "yes" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = cell.Value
.Subject = "Reminder"
.Body = "Hi, please find your account permissions below:"
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
所需的电子邮件输出将类似于:
您好,请在下面找到您的帐户权限:
+----------------+---------------------+---------+
| Email | Application | Version |
+----------------+---------------------+---------+
| test2@test.com | Microsoft_Office_13 | v2.0 |
| test2@test.com | Putty | v3.0 |
| test2@test.com | Adobe_Reader | v6.4 |
+----------------+---------------------+---------+
【问题讨论】:
-
也许this 有帮助