VBA:MailItem.CC 似乎不起作用
我有一些代码旨在自动发送带有附件的电子邮件。它一直工作得 100% 正常,但我现在也需要 CC 人员。我认为它应该很简单,并将 .CC 属性添加到我的 MailItem 中,但在我的一生中,我就是无法让它工作。
我在这里搜索过网络和其他问题,但没有找到任何解决办法。
我尝试过
EmailItem.Recipients.Add (CCStr)
EmailItem.Recipients.Add(CCStr).Type = olCC
,但这也不起作用。代码仍然会发送到 EmailItem.To 列出的电子邮件,但 CC 不起作用。我在下面发布了我的代码,非常感谢任何和所有帮助。
Dim Cust_Email As String
Dim Email As Outlook.Application
Set Email = New Outlook.Application
Dim EmailItem As Outlook.MailItem
Dim CCStr As String
E1: Cust_Email = InputBox("Please enter the email of your desired recipient." & vbCrLf &
vbCrLf & "Separate mutliple emails with a semicolon: ( ; )", "Who are we sending to?", "
[Enter email here]")
If StrPtr(Cust_Email) = 0 Then
GoTo Final
ElseIf Cust_Email = vbNullString Or Cust_Email = "[Enter email here]" Then
MsgBox "You must enter an email address to forward the quote(s) to.", vbOKOnly,
"Silly goose."
GoTo E1
End If
'
CCStr = InputBox("Please enter the email for any recipients you would like cc'd on these
emails. (Leave blank if none.)", "Carbon Copy?", "")
Set EmailItem = OutApp.CreateItem(olMailItem)
EmailItem.To = Cust_Email
EmailItem.CC = CCStr
EmailItem.Subject = "Title"
EmailItem.HTMLBody = "Text"
EmailItem.Attachments.Add (filename & ".pdf")
EmailItem.Send
Final: End Sub
谢谢你!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在代码中,您尝试将两个单独的收件人添加到集合中:
每次调用
Recipients.Add
方法时,都会将一个新收件人添加到集合中。您需要改用以下方法:设置项目的所有收件人后,不要忘记调用 Recipients.ResolveAll 方法,尝试解析
Recipients
集合中的所有Recipient
对象地址簿。您可以在 如何:以编程方式在 Outlook 中填写“收件人”、“抄送”和“密件抄送”字段一文。
In the code you have tried to add two separate recipients to the collection:
Each time you call the
Recipients.Add
method a new recipient is added to the collection. You need to use the following approach instead:After setting up all recipients for the item don't forget to call the Recipients.ResolveAll method which attempts to resolve all the
Recipient
objects in theRecipients
collection against the Address Book.You can read more about that in the How To: Fill TO,CC and BCC fields in Outlook programmatically article.