使用VBA向多个收件人发送电子邮件

7

我有以下的代码,允许我附加报告并将其发送给一个收件人。

如何发送到多个地址?

我尝试将地址放入数组中,但它会出现“类型不匹配”的错误。

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 = "chrissparkes@me.com"
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
2个回答

10

分号分隔的电子邮件地址:

strTO = "chrissparkes@me.com;you@me.com;thirdguy@there.org"

正如@HansUp在评论中提到的那样,如果你已经把电子邮件地址存储在一个数组中,你可以使用Join函数将其转换为以分号分隔的字符串:

strTO = Join(YourArrayVariable, ";")

0

strTO是一个字符串。

使用与手动输入到收件箱相同的格式。

strTO = "chrissparkes@me.com; another@me.com"


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接