excel vba,添加多个 .To 电子邮件地址

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27981236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 05:51:23  来源:igfitidea点击:

excel vba, add multiple .To email addresses

excelvbaexcel-vba

提问by SMORF

I am using the following code to send an email using VBA. But, no email is sent ... I think this is due to more than one email address in the '.To = ' code line. Is there a way of adapting the code to allow multiple email addresses?

我正在使用以下代码使用 VBA 发送电子邮件。但是,没有发送电子邮件......我认为这是由于 '.To = ' 代码行中有多个电子邮件地址。有没有办法调整代码以允许多个电子邮件地址?

I've tried looking at Ron de Bruin examples but, I just cant get anything to work?

我试过查看 Ron de Bruin 的例子,但是,我什么都做不了?

Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object

Set rng = Nothing
On Error Resume Next
Set rng = Selection.SpecialCells(xlCellTypeVisible)
On Error GoTo 0

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
    .To = "[email protected], [email protected]"
    .CC = ""
    .BCC = ""
    .Subject = "Open Orders where LF print to center of disc is required - " & Format(Now, "dd/mm/yyyy HH:mm")
    .HTMLBody = "Please ensure discs for the following orders are run on replication lines that allow LF print to be printed to the center of the disc. " & Chr(10) & _
    RangetoHTML(rng)
    .Send
End With

采纳答案by K?τ?

Use ; instead of ,

用 ; 代替 ,

.To = "[email protected]; [email protected]"

回答by duDE

Try to use the semicolon instead of comma:

尝试使用分号代替逗号:

With OutMail
    '.To = "[email protected], [email protected]"
    .To = "[email protected]; [email protected]"