Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
758 views
in Technique[技术] by (71.8m points)

ms access 2013 - Sending emails to multiple recipients using 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 = "[email protected]"
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 ReportsSkipLotReport.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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Semicolon-separated e-mail addresses:

strTO = "[email protected];[email protected];[email protected]"

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, ";")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...