简体   繁体   English

在 Outlook 2013 中使用 VBA 将密件抄送添加到电子邮件

[英]Add BCC to email with VBA in Outlook 2013

I can't figure out the correct VBA code for Outlook 2013 to add a fixed email address to the BCC field of an email while it is open for editing.我无法找出 Outlook 2013 的正确 VBA 代码,以便在电子邮件打开进行编辑时将固定电子邮件地址添加到电子邮件的密件抄送字段。 I have the following code, which creates the email and then sets the BCC.我有以下代码,它创建电子邮件然后设置密件抄送。

I want to add BCC to emails that I am replying to, so the message will already be in 'draft' form.我想在我正在回复的电子邮件中添加密件抄送,这样邮件就已经是“草稿”形式了。

Sub sendcomment_click()
Set oMsg = Application.CreateItem(olMailItem)

With oMsg
    .Recipients.Add ("email address")
    'Set objRecip = Item.Recipients.Add("email address")
    'objRecip.Type = olBCC
    'objRecip.Resolve

    ' Join Email addresses by "; " into ".BCC" as string
    .BCC = "Person.A@somewhere.com; Person.B@somewhere.com"

    .Subject = "New Comment by"
    .Body = "sdfsdfsdf"
    .Display ' Comment this to have it not show up
    '.Send ' Uncomment this to have it sent automatically
End With

Set oMsg = Nothing
End Sub

* Update * * 更新 *

I implemented the great advice from Dmitry我采纳了德米特里的好建议

My code now reads:我的代码现在是:

Sub BCC()
Dim objRecip As Recipient
Set oMsg = Application.ActiveInspector.CurrentItem

With oMsg

Set objRecip = item.Recipients.add("XXX@example.com")
objRecip.Type = olBCC
objRecip.Resolve

End With

Set oMsg = Nothing

End sub

However, when I try to run it I get an error "Run Time error '424' Object required" and it highlights the line:但是,当我尝试运行它时,出现错误“需要运行时错误 '424' 对象”并突出显示该行:

Set objRecip = item.Recipients.Add("xxx@example.com")

Instead of Application.CreateItem(olMailItem) , use Application.ActiveInspector.CurrentItem .而不是Application.CreateItem(olMailItem) ,使用Application.ActiveInspector.CurrentItem If you set the BCC property, you will wipe out all existing BCC recipients.如果您设置 BCC 属性,您将清除所有现有的 BCC 收件人。 Use Recipients.Add (you have it commented out above) for each email address.对每个电子邮件地址使用Recipients.Add (您已在上面注释掉)。

You need to define Item:您需要定义项目:

Sub Bcc()
Dim objApp As Outlook.Application
Set objApp = Application
Dim objRecip As Recipient
Dim Item As MailItem
Set Item = objApp.ActiveInspector.CurrentItem
With objMsg
Set objRecip = Item.Recipients.Add("XXX@example.com")
objRecip.Type = olBCC
objRecip.Resolve
End With
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM