我的VBA代码发送自动电子邮件。如何填写多个电子邮件地址?
用户创建新电子邮件并填写:
收件人:一个电子邮件地址
密件抄送:电子邮件地址2,电子邮件地址3,电子邮件地址4,...
Outlook如何分隔密件抄送属性中的每个电子邮件地址,以在我的示例中发送4封电子邮件而不是一封电子邮件。
Dim strWho As String
Dim strSubject As String
Dim objNewMail As Outlook.MailItem
Set objNewMail = Application.CreateItem(olMailItem)
strWho = objMail.To
strSubject = objMail.Subject
With objNewMail
.To = strWho
.BCC = "mail2,mail3,mail4,mail5"
.Subject = strSubject
.Display
.Send
End With
答案 0 :(得分:1)
您应使用分号;
来分隔每个邮件地址,并遵循以下格式:
"person1@email.com;person2@email.com"
如果您已经将它们键入到邮件对象中,则可以使用以下代码:
Dim strWho As String
Dim strSubject As String
Dim objNewMail As Outlook.MailItem
Dim bccMails As String
Set objNewMail = Application.CreateItem(olMailItem)
strWho = objMail.To
strSubject = objMail.Subject
bccMails = objMail.BCC
With objNewMail
.To = strWho
.BCC = bccMails
.Subject = strSubject
.Display
.Send
End With
否则,您可以向用户询问一次带有InputBox
的邮件地址,然后对每个邮件使用该值:
Dim bccMails As String
bccMails = InputBox("Please insert .bcc email addresses, separated by semicolons", "Email Address", "person1@email.com;person2@email.com")
希望这可以作为起点。