【问题标题】:Sending emails to multiple recipients using VBA使用 VBA 向多个收件人发送电子邮件
【发布时间】:2014-08-29 22:35:25
【问题描述】:

我有以下代码,可让我附上一份报告,然后将其发送给一位收件人。

如何将其发送到多个地址?

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

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

【问题讨论】:

    标签: vba ms-access-2013


    【解决方案1】:

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

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

    正如@HansUp 在评论中所说,如果您的电子邮件地址已经在数组中,则可以使用Join 函数将其转换为分号分隔的字符串:

    strTO = Join(YourArrayVariable, ";")
    

    【讨论】:

      【解决方案2】:

      strTO 是一个字符串。

      使用与您在“收件人”框中手动输入的格式相同的格式。

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

      【讨论】:

        猜你喜欢
        • 2012-05-18
        • 2014-06-22
        • 2022-01-02
        • 2017-12-05
        • 2015-08-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多