Aggiungere destinatari Ccn che utilizzano Outlook VBA
-
12-10-2019 - |
Domanda
Ho bisogno di aggiungere bcc destinatari di una e-mail caricati da un modello. I destinatari devono essere tutti i contatti in una determinata categoria. Ho il seguente finora, tranne che è estremamente inefficiente e provoca Outlook per non rispondere:
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
Soluzione
Quello che ho finito per fare stava muovendo newItem.Display
fino a poco prima Set newItem = Nothing
. Questo non può essere la soluzione più efficiente, ma ottiene il lavoro fatto senza causare un crash.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow