开发者

Add bcc recipients using Outlook VBA

开发者 https://www.devze.com 2023-02-05 07:32 出处:网络
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

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:

Sub Distribute_Newslet开发者_Go百科ter()
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. This may not be the most efficient solution, but it gets the job done without causing a crash.

0

精彩评论

暂无评论...
验证码 换一张
取 消