有时需要使用outlook批量发送电子邮件,经过上网查找,发现可以借助 VBA 帮助我们实现。代码如下:

    1. Sub send_email()
    2. ' Works in Excel 2000, Excel 2002, Excel 2003, Excel 2007, Excel 2010, Outlook 2000, Outlook 2002, Outlook 2003, Outlook 2007, Outlook 2010.
    3. ' This example sends the last saved version of the Activeworkbook object .
    4. Dim OutApp As Object
    5. Dim OutMail As Object
    6. Set OutApp = CreateObject("Outlook.Application")
    7. Set OutMail = OutApp.CreateItem(0)
    8. On Error Resume Next
    9. ' Change the mail address and subject in the macro before you run it.
    10. With OutMail
    11. .To = Range("C2").Value
    12. .CC = Range("D2").Value
    13. .BCC = ""
    14. .Subject = Range("E2").Value
    15. .Body = Range("F2").Value
    16. '.Attachments.Add ActiveWorkbook.FullName
    17. ' You can add other files by uncommenting the following line.
    18. .Attachments.Add (Range("G2").Value)
    19. ' In place of the following statement, you can use ".Display" to
    20. ' display the mail.
    21. .Display
    22. End With
    23. On Error GoTo 0
    24. Set OutMail = Nothing
    25. Set OutApp = Nothing
    26. End Sub

    image.png
    代码解释如下:
    .TO : 邮件发送给谁,代码中是 Range(“C2”).Value,只C2单元格的值;同理
    .CC: 是抄送人
    .BCC:暗抄送
    .Subject:邮件主题
    .Body:邮件正文
    .Attachments.Add:邮件附件,主要附件写上文件全部路径以及文件后缀名
    .Display:发送前是否显示,可以直接改成 .Send 直接发送