我无法找到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
*更新 *
我实施了dmitry的好建议
我的代码现在读取:
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")
而不是Application.CreateItem(olMailItem)
,使用Application.ActiveInspector.CurrentItem
。如果设置BCC属性,则将消灭所有现有的BCC收件人。每个电子邮件地址使用Recipients.Add
(您在上面评论了它)。
您需要定义项目:
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