[英]Add bcc recipients using Outlook VBA
I need to add bcc recipients to an email loaded from a template.我需要将密件抄送收件人添加到从模板加载的电子邮件中。 The recipients should be all of the contacts in a certain category.
收件人应该是某个类别中的所有联系人。 I have the following so far, except it is extremely inefficient and causes Outlook to become unresponsive:
到目前为止,我有以下几点,除了它效率极低并导致 Outlook 无响应:
Sub Distribute_Newsletter()
Set newItem = Application.CreateItemFromTemplate("P:\Subscription Templates\subscription template.oft")
newItem.Display
Set oNS = Application.GetNamespace("MAPI")
Set oContacts = oNS.Folders(1).Folders("Contacts")
Dim emailAddress As String
For Each oContactItem In oContacts.Items
If oContactItem.Class = olContact Then
emailAddress = oContactItem.Email1Address
If Not emailAddress = "" Then 'And oContactItem.Categories
Set objRecip = newItem.Recipients.Add(emailAddress)
objRecip.Type = olBCC
End If
End If
Next
Set oNS = Nothing
Set oContacts = Nothing
Set objRecip = Nothing
Set newItem = Nothing
End Sub
What I ended up doing was moving newItem.Display
down to just before Set newItem = Nothing
.我最终做的是将
newItem.Display
移到Set newItem = Nothing
之前。 This may not be the most efficient solution, but it gets the job done without causing a crash.这可能不是最有效的解决方案,但它可以在不导致崩溃的情况下完成工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.