首页 > 解决方案 > 按唯一标识符发送电子邮件,按 ID 分组 #

问题描述

我被这个困住了。我想要做的是循环每个 ID 并按支持联系人对它们进行分组,并通过电子邮件向这些人发送关于 ID 的电子邮件,它可能是电子邮件正文中的一个句子或表格。

ID      Support Name Support Contact Decision
MN-888  Qwe          qwe@yahoo.com   Yes
MN-111  Asd          asd@yahoo.com   Yes
MN-999  Qwe          qwe@yahoo.com   Yes
MN-034  Ppp          ppp@yahoo.com   Yes

期望的输出:

亲爱的奎,

请返回 ID #MN-888, MN-999

我卡住的代码

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("C").Cells.SpecialCells(xlCellTypeConstants)
    If cell.Value Like "?*@?*.?*" And _
       LCase(Cells(cell.Row, "D").Value) = "yes" Then

        Set OutMail = OutApp.CreateItem(0)
        On Error Resume Next
        With OutMail
            .To = cell.Value
            .Subject = "Reminder"
            .Body = "Dear " & Cells(cell.Row, "B").Value _
                  & vbNewLine & vbNewLine & _
                    "Please return ID # " & Cells(cell.Row, "A").Value _

            .Send  'Or use Display
        End With
        On Error GoTo 0
        Set OutMail = Nothing
    End If
    Next cell
cleanup:
    Set OutApp = Nothing
    Application.ScreenUpdating = True
End Sub

标签: excelvbaexcel-formula

解决方案


推荐阅读