Sub SendSalarySlips()
Dim OutlookApp As Object, OutlookMail As Object
Dim i As Long, lastRow As Long
Dim emailAddress As String, emailBody As String
Set OutlookApp = CreateObject(“Outlook.Application”)
lastRow = Cells(Rows.Count, “A”).End(xlUp).Row ‘ 获取数据最后一行
For i = 2 To lastRow ‘ 从第二行开始,第一行是表头
emailAddress = Cells(i, “C”).Value ‘ 邮箱地址在C列
emailBody = “尊敬的” & Cells(i, “B”).Value & “员工:\n\n” & _ ‘ 员工姓名在B列
“您的本月工资详情如下:\n\n” & _
“基本工资:” & Cells(i, “D”).Value & “\n” & _ ‘ 基本工资在D列
“绩效奖金:” & Cells(i, “E”).Value & “\n” & _ ‘ 绩效奖金在E列
“应发工资:” & Cells(i, “F”).Value & “\n” & _ ‘ 应发工资在F列
“实发工资:” & Cells(i, “G”).Value & “\n\n” & _ ‘ 实发工资在G列
“请注意查收,如有疑问请及时联系HR。\n\n” & _
“人力资源部敬上”
Set OutlookMail = OutlookApp.CreateItem(0)
With OutlookMail
.To = emailAddress
.Subject = “您的本月工资条”
.Body = emailBody
.Display ‘ 显示邮件,可以改为 .Send 直接发送
End With
Set OutlookMail = Nothing
Next i
Set OutlookApp = Nothing
MsgBox “工资条发送完成!”, vbInformation
End Sub
利唐i人事HR社区,发布者:ihreditor,转转请注明出处:https://www.ihr360.com/hrnews/20241225370.html