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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21365624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 01:32:52  来源:igfitidea点击:

Add BCC to email with VBA in Outlook 2013

vbaoutlookoutlook-vba

提问by Alastair Collier

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. I have the following code, which creates the email and then sets the BCC.

我无法找出 Outlook 2013 的正确 VBA 代码,以便在电子邮件打开进行编辑时将固定电子邮件地址添加到电子邮件的密件抄送字段。我有以下代码,它创建电子邮件然后设置密件抄送。

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 = "[email protected]; [email protected]"

    .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("[email protected]")
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("[email protected]")

回答by Dmitry Streblechenko

Instead of Application.CreateItem(olMailItem), use Application.ActiveInspector.CurrentItem. If you set the BCC property, you will wipe out all existing BCC recipients. Use Recipients.Add(you have it commented out above) for each email address.

而不是Application.CreateItem(olMailItem),使用Application.ActiveInspector.CurrentItem。如果您设置 BCC 属性,您将清除所有现有的 BCC 收件人。Recipients.Add为每个电子邮件地址使用(您已在上面注释掉)。

回答by Mostafa Bedoor

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("[email protected]")
objRecip.Type = olBCC
objRecip.Resolve
End With
End Sub