如何用EXCEL?

Tags: 郵件, 工資條,

每個月工資條如何發放給大家是一個頭疼的事情,因為工資涉及到保密問題,用郵件吧,每個人的郵件內容都有些不一樣的地方,人一多就特別容易出錯;光這個發工資條就夠讓人忙活好長時間的了;現在跟大家分享一下EXCEL 批量發送郵件批量發送工資條!

工具/原料

工資明細(內含郵箱地址哦)

啟用EXCEL的開發工具選項卡

方法/步驟

按照下圖整理工資明細表

親!格式不一樣也可以哦,需要微調代碼啊!

如何用EXCEL 批量發送郵件批量發送工資條

啟用開發工具選項卡;插入命令控件;修改控件名稱及顯示名;

如何用EXCEL 批量發送郵件批量發送工資條

如何用EXCEL 批量發送郵件批量發送工資條

進入VBA編程界面;複製以下代碼到編輯窗口。

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 = "你好
  " + Cells(rowCount, 2) + Cells(rowCount, 6) + "

  以下是你" + Cells(1, 1) + "明細如下:" + _ "

'設置附件(從通訊錄表的“附件”字段中獲得),沒有附件的話可以刪除此句

.Attachments.Add Cells(rowCount, 24).Value

'自動發送郵件

.Send

End With

'銷燬objMail對象

Set objMail = Nothing

Next

'銷燬objOutlook對象

Set objOutlook = Nothing

'所有電子郵件發送完成時提示

MsgBox rowCount - 3 & "個員工的工資單發送成功!"

End Sub

如何用EXCEL 批量發送郵件批量發送工資條

大功告成,測試圖如下

如何用EXCEL 批量發送郵件批量發送工資條

注意事項

提示:發送全可以先斷網啊,點擊後再去郵箱內的發件箱看效果怎麼樣,不行可以刪除重來的。

實例文檔下載地址:

" + _ " " + _ " " + _ " " + _ " " + _ " " + _ " " + _ " " + _ " " + _ " " + _ " " + _ " " + _ " "
工資表
" + 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)) + "
相關問題答案