2014-08-27 6 views
5

Ich habe den folgenden Code, mit dem ich einen Bericht anhängen und dann an einen Empfänger senden kann.Senden von E-Mails an mehrere Empfänger mit VBA

Wie sende ich es an mehr als eine Adresse?

Ich habe versucht, die Adressen in ein Array zu setzen, aber es gibt einen "Type Mismatch" -Fehler.

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 

Antwort

7

Semikolon getrennte E-Mail-Adressen:

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

Wie @HansUp bemerkte in einem Kommentar, wenn Sie Ihre E-Mail-Adressen, die bereits in einem Array haben, können Sie die Join Funktion verwenden, um die Umrechnung zu einer durch Semikolon getrennten Zeichenfolge:

strTO = Join(YourArrayVariable, ";")