Frage

Ich brauche bcc Empfänger aus einer Vorlage geladen zu einer E-Mail hinzuzufügen. Die Empfänger sollten alle Kontakte in einer bestimmten Kategorie sein. Ich habe folgendes bisher, außer es extrem ineffizient und verursacht Outlook nicht mehr zu reagieren:

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
War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top