我有以下代码,允许我附加报告,然后将其发送给一个收件人。
如何将其发送到多个地址?
我已经尝试将地址放在一个数组中,但是它提供了一个" Type Mismatch"错误。
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
答案 0 :(得分:9)
以分号分隔的电子邮件地址:
strTO = "chrissparkes@me.com;you@me.com;thirdguy@there.org"
正如@HansUp在评论中所说,如果您的电子邮件地址已经在数组中,则可以使用Join
函数将其转换为以分号分隔的字符串:
strTO = Join(YourArrayVariable, ";")
答案 1 :(得分:0)
strTO是一个字符串。
使用与在“收件人”框中手动输入相同的格式。
strTO =&#34; chrissparkes@me.com; another@me.com"