使用VBA向多个收件人发送电子邮件 [英] Sending emails to multiple recipients using VBA

查看:540
本文介绍了使用VBA向多个收件人发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,可让我附加报告,然后将其发送给一个收件人.

I have the following code which allows me to attach a report then send it to one recipient.

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

How do I send it to more than one address?

我尝试将地址放入数组中,但是会出现类型不匹配"错误.

I've tried putting the addresses in an array but it gives a "Type Mismatch" error.

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

推荐答案

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

Semicolon-separated e-mail addresses:

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

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

As @HansUp remarked in a comment, if you have your email addresses already in an array, you can use the Join function to convert it to a semicolon-delimited string:

strTO = Join(YourArrayVariable, ";")

这篇关于使用VBA向多个收件人发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆