我无法确定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")
答案 0 :(得分:5)
而不是Application.CreateItem(olMailItem)
,请使用Application.ActiveInspector.CurrentItem
。
如果设置BCC属性,则将清除所有现有BCC收件人。每个电子邮件地址都使用Recipients.Add(您已将其注释掉)。
答案 1 :(得分:1)
您需要定义项目:
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