2014-08-27 281 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

分號分隔的電子郵件地址:

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

由於@HansUp說在一個評論,如果您在數組中有你的電子郵件地址已經,您可以使用Join功能將其轉換以分號分隔的字符串:

strTO = Join(YourArrayVariable, ";") 
相關問題