2014-08-27 17 views
5

Tôi có mã sau đây cho phép tôi đính kèm báo cáo rồi gửi cho một người nhận.Gửi email tới nhiều người nhận bằng cách sử dụng VBA

Tôi làm cách nào để gửi nhiều địa chỉ?

Tôi đã thử đặt các địa chỉ vào một mảng nhưng nó cung cấp lỗi "Loại không phù hợp".

Dim strReportName As String 
Dim oLook As Object 
Dim oMail As Object 
Dim olns As Outlook.Namespace 
Dim strTO As String 
Dim strCC As String 
Dim strMessageBody As String 
Dim strSubject As String 

Set oLook = CreateObject("Outlook.Application") 
'Set olns = oLook.GetNamespace("MAPI") 
Set oMail = oLook.CreateItem(0) 

'*********************** USER DEFINED SECTION ************************ 
strTO = "[email protected]" 
strMessageBody = "<---This is an automatically generated email. Please do not respond.---->" 
strSubject = "Daily Skip" 
'********************************************************************* 

With oMail 
.To = strTO 
.CC = strCC 
.Body = strMessageBody 
.Subject = strSubject 

.Attachments.Add "C:\Output Reports\SkipLotReport.xlsx" 
.Send 
End With 

Set oMail = Nothing 
Set oLook = Nothing 
'Set olns = Nothing 


'DB.Close 
'tbloutput.Close 
'dbLocal.Close 
objWorkbook.Close 

'Set objmail = Nothing 
'Set DB = Nothing 
Set tbloutput = Nothing 


Set objWorksheet = Nothing 
Set objWorkbook = Nothing 
Set objExcel = Nothing 
Set tbloutput = Nothing 
Set dbLocal = Nothing 

Trả lời

7

địa chỉ email chấm phẩy phân cách:

strTO = "[email protected];[email protected];[email protected]" 

Như @HansUp nhận xét trong một chú thích, nếu bạn có địa chỉ email của bạn đã có trong một mảng, bạn có thể sử dụng Join chức năng để chuyển đổi nó thành một chuỗi được phân cách bằng dấu chấm phẩy:

strTO = Join(YourArrayVariable, ";") 
Các vấn đề liên quan