關閉→
當前位置:知科普>IT科技>批量發送郵件批量發送工資條 - 如何用EXCEL

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

知科普 人氣:1.59W
如何用EXCEL 批量發送郵件批量發送工資條呢?接下來為大家介紹一下

方法

打開要發送的工資

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

啟用開發工具

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

點擊【插入】

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

選擇【命令控件】

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

點擊【右鍵】,選擇【屬性】

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

雙擊圖中區域進入VBA編程界面

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

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

【輸入】Private Sub CommandButton1_Click()
'要能正確發送並需要對Microseft Outlook進行有效配置
On Error Resume Next
Dim rowCount, endRowNo, endColumnNo, sFile$, sFile1$, A&, B&
Dim objOutlook As Object
Dim objMail As MailItem
'取得當前工作表數據區行數列數
endRowNo = ActiveSheet.UsedRange.Rows.Count
endColumnNo = ActiveSheet.UsedRange.Columns.Count

'取得當前工作表的名稱,用來作為郵件主題進行發送
sFile1 = ActiveSheet.Name
'創建objOutlook為Outlook應用程序對象
Set objOutlook = CreateObject("Outlook.Application")

'開始循環發送電子郵件
For rowCount = 2 To endRowNo
'創建objMail為一個郵件對象
Set objMail = objOutlook.CreateItem(olMailItem)

With objMail

'設置收件人地址,數據源所在列數
.To = Cells(rowCount, 5)

'設置抄送人地址(從通訊錄表的'E-mail地址'字段中獲得)
'.CC = Cells(rowCount, 0)
'設置郵件主題,取值工作表名,
.Subject = sFile1
'設置郵件內容(從通訊錄表的“內容”字段中獲得)
'align單元格文本顯示方式 left(向左)、center(居中)、right(向右),默認是center, width-寬 height-高border 單元格線粗細,bordercolor返回或設置對象的邊框顏色
'colSpan是一種程式語言,其屬性可設置或返回表元橫跨的列數


sFile = "<tr>您好!<br> 以下是您" + sFile1 + ",請查收!</tr>"
sFile = sFile + "<table align='left' width='500' height='25' border= 1 bordercolor='#000000'> <tbody> "
sFile = sFile + "<tr><td colspan ='4' align='center'> 工資表</td> </tr> "
B = 1
For A = 1 To endColumnNo
'數據表頭中添加“X”後將不發送此字段
If Application.WorksheetFunction.CountIf(Cells(1, A), "*X*") = 0 Then
If B = 1 Then
sFile = sFile + "<tr><td width='20%' height='25'> " + Cells(1, A).Text + " </td> <tdwidth='30%' height='25'> " + Cells(rowCount, A).Text + "</td>"
B = 0

Else
sFile = sFile + "<td width='20%' height='25'> " + Cells(1, A).Text + " </td> <tdwidth='30%' height='25'> " + Cells(rowCount, A).Text + "</td> </tr>"
B = 1
End If
End If
Next

.HTMLBody = sFile


'設置附件(從通訊錄表的“附件”字段中獲得)
.Attachments.Add Cells(rowCount, 24).Value
'自動發送郵件
.Send
End With

'銷燬objMail對象
Set objMail = Nothing
Next
'銷燬objOutlook對象
Set objOutlook = Nothing
'所有電子郵件發送完成時提示
MsgBox rowCount - 2 & "個員工的工資單發送成功!"

End Sub

如何用EXCEL 批量發送郵件批量發送工資條 第8張
TAG標籤:#批量 #工資條 #郵件 #excel #發送 #