来自Excel单元的电子邮件地址返回该地址无效的消息
我创建了一个Excel宏,该宏可以使用模板生成电子邮件,并将其保存在草稿文件夹中,以便由我的团队成员发送。
是时候发送消息了,它会返回地址无效的消息。
地址正确。手动填充电子邮件是发送的。
Sub create_email()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim OutAccount As Outlook.Account
For linha = 2 To 16
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItemFromTemplate(' .oft file path)
Set OutAccount = OutApp.Session.Accounts.Item(2)
With OutMail
.To = Cells(linha, 1).Value
.CC = ' CC address
.BCC = ' BCC address
.Subject = ' text & Cells(linha, 2)
strFile = ""
strFile = Dir(" ' file path ")
If strFile <> "" Then
.Attachments.Add (ThisWorkbook.Path & "\Base - " & Cells(linha, 2).Value & ".xlsx")
.SendUsingAccount = OutAccount
.Save
Else
GoTo Fim
End If
Fim:
End With
Next
Set OutMail = Nothing
Set OutApp = Nothing
Set OutAccount = Nothing
End Sub
对于每个电子邮件地址,该代码都会陷入此问题。如果我将其更改为一个联系人名称组,则会创建相同的问题。
所有电子邮件都显示在草稿文件夹中,正确分开。
I created an Excel macro that generates e-mails using a template and saves it in draft folders so it can be sent by a member of my team.
When it's time to send the message, it returns the message that the address is invalid.
The address is correct. Filling it manually the e-mail is sent.
Sub create_email()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim OutAccount As Outlook.Account
For linha = 2 To 16
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItemFromTemplate(' .oft file path)
Set OutAccount = OutApp.Session.Accounts.Item(2)
With OutMail
.To = Cells(linha, 1).Value
.CC = ' CC address
.BCC = ' BCC address
.Subject = ' text & Cells(linha, 2)
strFile = ""
strFile = Dir(" ' file path ")
If strFile <> "" Then
.Attachments.Add (ThisWorkbook.Path & "\Base - " & Cells(linha, 2).Value & ".xlsx")
.SendUsingAccount = OutAccount
.Save
Else
GoTo Fim
End If
Fim:
End With
Next
Set OutMail = Nothing
Set OutApp = Nothing
Set OutAccount = Nothing
End Sub
The code runs into this issue for every e-mail address. If I change it for a contact name group, it creates the same issue.
All e-mails appear in the draft folder correctly separated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
resolveall 可能会触发地址更新。
注意:当收件人在电子邮件地址格式中不是时,链接中的示例中的测试适用。
ResolveAll may trigger an address update.
Note: The test in the example in the link applies when the recipient is not in email address format.