有时需要使用outlook批量发送电子邮件,经过上网查找,发现可以借助 VBA 帮助我们实现。代码如下:
Sub send_email()' Works in Excel 2000, Excel 2002, Excel 2003, Excel 2007, Excel 2010, Outlook 2000, Outlook 2002, Outlook 2003, Outlook 2007, Outlook 2010.' This example sends the last saved version of the Activeworkbook object .Dim OutApp As ObjectDim OutMail As ObjectSet OutApp = CreateObject("Outlook.Application")Set OutMail = OutApp.CreateItem(0)On Error Resume Next' Change the mail address and subject in the macro before you run it.With OutMail.To = Range("C2").Value.CC = Range("D2").Value.BCC = "".Subject = Range("E2").Value.Body = Range("F2").Value'.Attachments.Add ActiveWorkbook.FullName' You can add other files by uncommenting the following line..Attachments.Add (Range("G2").Value)' In place of the following statement, you can use ".Display" to' display the mail..DisplayEnd WithOn Error GoTo 0Set OutMail = NothingSet OutApp = NothingEnd Sub

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