VBA:MailItem.CC 似乎不起作用

发布于 2025-01-17 01:39:52 字数 1412 浏览 2 评论 0 原文

我有一些代码旨在自动发送带有附件的电子邮件。它一直工作得 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

谢谢你!

I've got some code designed to automatically send emails with attachments. It's been working 100% fine but I am now required to CC people as well. I thought it should be simple and added the .CC property to my MailItem but for the life of me I just can't get it to work.

I've searched the web and other questions on here but haven't been able to get anything to work.

I tried

EmailItem.Recipients.Add (CCStr)
EmailItem.Recipients.Add(CCStr).Type = olCC

but that didn't work either. The code still sends to the email listed by EmailItem.To just fine but the CC just doesn't work. I've posted my code below, any and all help is greatly appreciated.

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

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柒七 2025-01-24 01:39:52

在代码中,您尝试将两个单独的收件人添加到集合中:

EmailItem.Recipients.Add (CCStr)
EmailItem.Recipients.Add(CCStr).Type = olCC

每次调用 Recipients.Add 方法时,都会将一个新收件人添加到集合中。您需要改用以下方法:

recipientCC = recipients.Add("Eugene Astafiev")
recipientCC.Type = OlMailRecipientType.olCC;  

设置项目的所有收件人后,不要忘记调用 Recipients.ResolveAll 方法,尝试解析 Recipients 集合中的所有 Recipient 对象地址簿。

您可以在 如何:以编程方式在 Outlook 中填写“收件人”、“抄送”和“密件抄送”字段一文。

In the code you have tried to add two separate recipients to the collection:

EmailItem.Recipients.Add (CCStr)
EmailItem.Recipients.Add(CCStr).Type = olCC

Each time you call the Recipients.Add method a new recipient is added to the collection. You need to use the following approach instead:

recipientCC = recipients.Add("Eugene Astafiev")
recipientCC.Type = OlMailRecipientType.olCC;  

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 the Recipients 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文