網站首頁 學習教育 IT科技 金融知識 旅遊規劃 生活小知識 家鄉美食 養生小知識 健身運動 美容百科 遊戲知識 綜合知識
當前位置:趣知科普吧 > IT科技 > 

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

欄目: IT科技 / 發佈於: / 人氣:1.69W
如何用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張