【问题标题】:Send emails using VBA from Excel sheet with multiple recipients - pull in date and attachment使用具有多个收件人的 Excel 工作表中的 VBA 发送电子邮件 - 提取日期和附件
【发布时间】:2022-12-20 07:44:40
【问题描述】:

我正在使用 VBA 代码从 Excel 工作表发送电子邮件:
示例 Excel 工作表
[![在此处输入图片描述][1]][1]

我使用代码为 C 列中的每个电子邮件地址生成一封单独的电子邮件,并附有一个文件。

我希望将代码添加到:

  1. 将 D 列中的日期拉入电子邮件正文。
    我已经在我希望日期所在的位置输入了电子邮件正文的代码。
    如何逐行获取每封电子邮件的日期。
  2. 如果 E 列中有链接,请将附加文件附加到电子邮件中。
    这将是对代码中已有内容的补充。

    Excel 工作表中的每一行都应使用 C 列中的电子邮件地址、D 列中的日期和 E 列中的附件生成单独的电子邮件。

【问题讨论】:

  • 如果你研究你找到的代码,你可以弄清楚这一点。

标签: excel vba email outlook


【解决方案1】:

假设其余代码有效,只需将 with-block 更新为:

With MItem
    .To = sourceWorksheet.Cells(RowIndex, 3).Value
    .Subject = "Subject Here"
    If Cells(RowIndex, 5) <> "" Then .Attachments.Add Cells(RowIndex, 5).Value
    If Cells(RowIndex, 6) <> "" Then .Attachments.Add Cells(RowIndex, 6).Value
    .HTMLBody = "<font face = ""Calibri(Body)"" font size=""3"" color=""black""><p>Good afternoon, </p>" & _
    "<p><strong>Please review the attached and return by " & Cells(RowIndex, 4) & ". </strong>  </p></font>" & .HTMLBody
     .Display
End With

【讨论】:

  • 太感谢了!我还有一个问题 - 当 C 列中没有电子邮件地址时,代码会生成一封电子邮件。我希望它跳过任何没有电子邮件地址的行 - 你能建议添加代码吗?我尝试在 .To 之前添加 If Cells(RowIndex, 3) <> "" 但它没有用。
  • 嗨 Sharon,只需在 With MItem 之前添加 if sourceWorksheet.Cells(RowIndex, 3) &lt;&gt; "" then 并在 End With 之后添加 End if
猜你喜欢
  • 1970-01-01
  • 2018-04-16
  • 1970-01-01
  • 1970-01-01
  • 2014-08-17
  • 1970-01-01
  • 1970-01-01
  • 2015-05-28
  • 2012-05-18
相关资源
最近更新 更多