2011-01-19 46 views
1

我需要將密件抄送收件人添加到從模板加載的電子郵件中。收件人應該是某個類別中的所有聯繫人。我有以下的,到目前爲止,除了它是非常低效和導致Outlook無法響應:使用Outlook VBA添加密件抄送收件人

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 

回答

0

我最終什麼事做搖newItem.Display下降到只有前Set newItem = Nothing。這可能不是最有效的解決方案,但它可以完成工作而不會導致崩潰。

相關問題