发送电子邮件给多个收件人vba

我正在尝试将一封邮件发送给多个收件人,但是我只能将其发送给最后一个人。 请帮我解决这个问题。

这里是我有的程序:

Sub Mail_Sending_WholWorkbook_Attachment() ' ' Mail_Sending_WholWorkbook_Attachment Macro ' This Macro is used to send the Bidresponse of the day as an attachment to the whole team with cc to santosh ' ' Keyboard Shortcut: Ctrl+Shift+B ' 'Working in Excel 2000-2016 'This example send the last saved version of the Activeworkbook 'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm Dim OutApp As Object Dim OutMail As Object Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .to = "nagarjun.balarama@accenture.com" .to = "nagarjun.b@bp.com" .to = "nagarjungupta@yahoo.com" .to = "nagarjunguptab@gmail.com" .CC = "" .BCC = "" .Subject = "BID RESPONSE" .Body = "THIS IS AN AUTOMATIC MAIL SENT THROUGH MACROS." & vbNewLine & " " & vbNewLine & "Hi Team," & vbNewLine & " " & vbNewLine & "Attached is the bid response for the day." & vbNewLine & " " & vbNewLine & "Thanks & Regards," & vbNewLine & "Nagarjun B" .Attachments.Add ActiveWorkbook.FullName 'You can add other files also like this '.Attachments.Add ("C:\test.txt") .Send 'or use .Display End With On Error GoTo 0 Set OutMail = Nothing Set OutApp = Nothing End Sub 

代码应该是:

 With OutMail .to = "nagarjun.balarama@accenture.com;nagarjun.b@bp.com;nagarjungupta@yahoo.com;nagarjunguptab@gmail.com" .CC = "" .BCC = "" .Subject = "BID RESPONSE" .Body = "THIS IS AN AUTOMATIC MAIL SENT THROUGH MACROS." & vbNewLine & " " & vbNewLine & "Hi Team," & vbNewLine & " " & vbNewLine & "Attached is the bid response for the day." & vbNewLine & " " & vbNewLine & "Thanks & Regards," & vbNewLine & "Nagarjun B" .Attachments.Add ActiveWorkbook.FullName 'You can add other files also like this '.Attachments.Add ("C:\test.txt") .Send 'or use .Display End With On Error GoTo 0 

我想你只是用最新的收件人覆盖“到”的价值。 您需要使用分号作为分隔符来附加收件人。

请用 ; (分号)如下,

 .to = "nagarjun.balarama@accenture.com" & ";" & "nagarjun.b@bp.com" & ";" & "nagarjungupta@yahoo.com" & ";" & "nagarjunguptab@gmail.com" 

要么

您也可以在另外的表单中声明电子邮件ID并引用单元格值。

 .to = Join(Application.Transpose(Worksheets("Sheet1").Range("A1:A4").Value), ";")