Tôi đang cố gắng thiết lập một số nút trên biểu mẫu Excel để gửi email cho các nhóm người khác nhau. Tôi đã thực hiện một số phạm vi ô trên một trang tính riêng biệt để liệt kê các địa chỉ email riêng biệt. Ví dụ, tôi muốn "Nút A" để mở Outlook và đặt danh sách các địa chỉ email từ "Worksheet B: Cells D3-D6". Sau đó, tất cả những gì phải làm là nhấn "Gửi" trong Outlook.Làm cách nào để sử dụng Outlook để gửi email cho nhiều người nhận trong Excel VBA
Đây là mã VBA của tôi cho đến nay, nhưng tôi không thể làm cho nó hoạt động. Ai đó có thể cho tôi biết những gì tôi đang thiếu hoặc làm sai, xin vui lòng?
VB:
Sub Mail_workbook_Outlook_1()
'Working in 2000-2010
'This example send the last saved version of the Activeworkbook
Dim OutApp As Object
Dim OutMail As Object
EmailTo = Worksheets("Selections").Range("D3:D6")
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = EmailTo
.CC = "[email protected];[email protected]"
.BCC = ""
.Subject = "RMA #" & Worksheets("RMA").Range("E1")
.Body = "Attached to this email is RMA #" & Worksheets("RMA").Range("E1") & ". Please follow the instructions for your department included in this form."
.Attachments.Add ActiveWorkbook.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Display
End With
On Error Goto 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
bạn cũng có thể sử dụng [Recipient.Add] (http://stackoverflow.com/questions/13019651/automated-email-generation-not-resolving-multiple- người nhận) – SeanC