使用Outlook 2013中的VBA将BCC添加到电子邮件中

 C1_VISION 发布于 2023-01-31 12:16

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

我想将BCC添加到我要回复的电子邮件中,因此该消息已经是"草稿"形式.

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

*更新*

我实施了德米特里的伟大建议

我的代码现在写道:

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

但是,当我尝试运行它时,我收到错误"运行时错误'424'对象需要"并突出显示该行:

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

Dmitry Streb.. 5

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

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有