在电子邮件通知工具

时间:2018-03-14 15:20:47

标签: vba excel-vba excel

我设置了一个通知工具,在报告到期前一天向我们的团队发送电子邮件。宏循环通过范围J2到J500以检查日期是否等于今天并检查范围L2到L500中的标记是否为TRUE然后发送该行的电子邮件。每个邮件的正文由单元格K2到K500中的连接文本公式组成。宏中的所有内容都可以正常工作,除了对K2到K500上每个电子邮件正文的引用,这会导致错误类型不匹配。请参阅以下代码:

Sub email()

'Purpose: send notification to team the day before report due date and if the report_
hasn't been completed or submitted.

Dim r As Range
Dim cell As Range

Set r = Range("J2:J500")

For Each cell In r

    If cell.Value = Date And cell.Offset(0, 2).Value = True Then

        Dim Email_Subject, Email_Send_From, Email_Send_To, _
        Email_Cc, Email_Bcc, Email_Body As String
        Dim Mail_Object, Mail_Single As Variant

        Email_Subject = "Report notification"
        Email_Send_From = "me@company.com"
        Email_Send_To = "team@company.com"
        Email_Cc = ""
        Email_Bcc = ""

'****the following line is the only problem with the macro****
        Email_Body = r.Offset(0,1).Value


        Set Mail_Object = CreateObject("Outlook.Application.16")
        Set Mail_Single = Mail_Object.CreateItem(0)
        With Mail_Single
        .Subject = Email_Subject
        .To = Email_Send_To
        .cc = Email_Cc
        .BCC = Email_Bcc
        .Body = Email_Body
        .Display
        End With

    End If

Next

    End Sub

如何正确引用每一行以获取相应的电子邮件正文?

0 个答案:

没有答案