2014-08-27 3 views
5

다음 코드를 사용하면 보고서를 첨부하여 한 명의 수신자에게 보낼 수 있습니다.VBA를 사용하여 여러 수신자에게 전자 메일 보내기

하나 이상의 주소로 보내려면 어떻게해야합니까?

배열에 주소를 넣으려고했지만 "형식 불일치"오류가 발생합니다.

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 

답변

7

세미콜론으로 구분 된 이메일 주소 : @HansUp으로

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

는 배열에 이미 이메일 주소가있는 경우, 당신이 그것을 변환 할 Join 기능을 사용할 수 있습니다 댓글에 주목 세미콜론으로 구분 된 문자열 :

strTO = Join(YourArrayVariable, ";") 
관련 문제