這是代碼:從Excel工作表中檢索多個收件人姓名
它適用於一個收件人。
Sub Sendmail()
Dim olItem As outlook.MailItem
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSht As Excel.Worksheet
Dim sPath As String
Dim iRow As Long
sPath = "***"
' // Excel
Set xlApp = CreateObject("Excel.Application")
' // Workbook
Set xlBook = xlApp.Workbooks.Open(sPath)
' // Sheet
Set xlSht = xlBook.Sheets("Sheet1")
' // Create e-mail Item
Set olItem = Application.CreateItem(olMailItem)
With olItem
.To = xlSht.Range("A1")
.CC = xlSht.Range("c1")
.subject = "test"
.Display
.Send
End With
' // Close
xlBook.Close SaveChanges:=True
' // Quit
xlApp.Quit
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSht = Nothing
Set olItem = Nothing
End Sub
查詢:按我的要求收件人姓名應採取 從鏈接Excel工作表。
所有收件人的郵件地址放在Excel 工作表的A列中。
而這些值是動態的,它可能包含任何數量的郵件 ID。
實施例:
柱A:
[email protected] [email protected] [email protected] [email protected]
在這裏有4個值,現在郵件應同時發送給所有這些收件人。
所以要字段應包含: [email protected]; [email protected]; [email protected]; [email protected]
的代碼應該能夠向下遍歷列A至最後 行並串聯所有用分號隔開的值(;)
使用'For'循環。 –
謝謝,使用循環郵件一次可以發送給一個收件人。 – Sai