gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 18:10:31 26 4
gpt4 key购买 nike

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

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

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

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

最佳答案

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

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

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

strTO = Join(YourArrayVariable, ";")

关于vba - 使用 VBA 向多个收件人发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25524955/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com