我正在尝试向多个收件人发送一封邮件,但我只能将其发送给最后一个人。请帮我解决问题。
这是我的程序:
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
答案 0 :(得分:3)
代码应为:
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
答案 1 :(得分:2)
我认为你只是覆盖"到"与最新收件人的价值。 您需要使用分号作为分隔符附加收件人。
答案 2 :(得分:1)
请使用; (分号)如下,
.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), ";")