如何用Excel群发邮件实现批量发送
分类:默认分类
浏览:30
2024-10-09
Sub SendEmails() Dim OutlookApp As Object Dim OutlookMail As Object Dim ws As Worksheet Dim lastRow As Long Dim i As Long ' 创建Outlook应用对象 Set OutlookApp = CreateObject("Outlook.Application") ' 获取当前工作表 Set ws = ThisWorkbook.Sheets("Sheet1") ' 获取最后一行 lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row ' 循环遍历每一行数据 For i = 2 To lastRow ' 创建邮件对象 Set OutlookMail = OutlookApp.CreateItem(0) With OutlookMail .To = ws.Cells(i, 2).Value ' 收件人邮箱 .Subject = "这是一个测试邮件" ' 邮件主题 .Body = "亲爱的 " & ws.Cells(i, 1).Value & "," & vbCrLf & vbCrLf & ws.Cells(i, 3).Value ' 邮件内容 .Send ' 发送邮件 End With Next i ' 释放对象 Set OutlookMail = Nothing Set OutlookApp = Nothing MsgBox "邮件发送完成!" End Sub这段代码会读取Excel表格中的数据,并通过Outlook发送邮件。你可以根据自己的需要修改邮件的主题和内容。