Private Sub 全自动发送邮件_Click()
'要能正确发送并需要对Microseft Outlook进行有效配置
On Error Resume Next
Dim rowCount, endRowNo
Dim objOutlook As New Outlook.Application
Dim objMail As MailItem
'取得当前工作表与Cells(1,1)相连的数据区行数
endRowNo = Cells(1, 1).CurrentRegion.Rows.Count
'创建objOutlook为Outlook应用程序对象
Set objOutlook = New Outlook.Application
'开始循环发送电子邮件
For rowCount = 3 To endRowNo
'创建objMail为一个邮件对象
Set objMail = objOutlook.CreateItem(olMailItem)
With objMail '设置收件人地址(从通讯录表的“E-mail地址”字段中获得)
.To = Cells(rowCount, 5) '设置抄送人地址(从通讯录表的'E-mail地址'字段中获得)
'.CC = Cells(rowCount, 0)
'设置邮件主题Cells(1, 1)是主题所在单元格a1单元格值,Cells(2, 1)是a2单元格值
.Subject = Cells(1, 1)
'设置邮件内容(从通讯录表的“内容”字段中获得) 'align 单元格文本显示方式 left(向左)、center(居中)、right(向右),默认是center, width-宽 height-高 border 单元格线粗细,bordercolor返回或设置对象的边框颜色 'colSpan是一种编程语言,其属性可设置或返回表元横跨的列数
'Cells(rowCount, 2) B列数据姓名,如果你的姓名不在B列,修改数字2,以此类推,如果用不了这么多列可以删除哦
.HTMLBody = "你好 '设置附件(从通讯录表的“附件”字段中获得),没有附件的话可以删除此句 .Attachments.Add Cells(rowCount, 24).Value '自动发送邮件 .Send End With '销毁objMail对象 Set objMail = Nothing Next '销毁objOutlook对象 Set objOutlook = Nothing '所有电子邮件发送完成时提示 MsgBox rowCount - 3 & "个员工的工资单发送成功!" End Sub 以上是VBA宏程序代码,根据每个人的模板条进行程序修改即可适用。 如需共同探讨提高,可以q 联系我 180 3.9322
" + Cells(rowCount, 2) + Cells(rowCount, 6) + "
以下是你" + Cells(1, 1) + "明细如下:" + _ "
" + _ " 工资表 " + _ " " + Cells(2, 1) + " " + Cells(rowCount, 1) + " " + Cells(2, 2) + " " + Cells(rowCount, 2) + " " + _ " " + Cells(2, 3) + " " + Cells(rowCount, 3) + " " + Cells(2, 4) + " " + Cells(rowCount, 4) + " " + _ " " + Cells(2, 5) + " " + Cells(rowCount, 5) + " " + Cells(2, 6) + " " + Cells(rowCount, 6) + " " + _ " " + (Cells(2, 7)) + " " + Str(Cells(rowCount, 7)) + " " + (Cells(2, 8)) + " " + Str(Cells(rowCount, 8)) + " " + _ " " + (Cells(2, 9)) + " " + Str(Cells(rowCount, 9)) + " " + (Cells(2, 10)) + " " + Str(Cells(rowCount, 10)) + " " + _ " " + (Cells(2, 11)) + " " + Str(Cells(rowCount, 11)) + " " + (Cells(2, 12)) + " " + Str(Cells(rowCount, 12)) + " " + _ " " + (Cells(2, 13)) + " " + Str(Cells(rowCount, 13)) + " " + (Cells(2, 14)) + " " + Str(Cells(rowCount, 14)) + " " + _ " " + (Cells(2, 15)) + " " + Str(Cells(rowCount, 15)) + " " + (Cells(2, 16)) + " " + Str(Cells(rowCount, 16)) + " " + _ " " + (Cells(2, 17)) + " " + Str(Cells(rowCount, 17)) + " " + (Cells(2, 18)) + " " + Str(Cells(rowCount, 18)) + " " + _ " " + (Cells(2, 19)) + " " + Str(Cells(rowCount, 19)) + " " + (Cells(2, 20)) + " " + Str(Cells(rowCount, 20)) + " " + _ " " + (Cells(2, 21)) + " " + Str(Cells(rowCount, 21)) + " " + (Cells(2, 22)) + " " + Str(Cells(rowCount, 22)) + " "
" + (Cells(2, 23)) + " " + Str(Cells(rowCount, 23)) + "