Note that there are some explanatory texts on larger screens.

plurals
  1. POForce the `Recipients` object to update when the To: text box has been edited
    primarykey
    data
    text
    <p>I sort recipients when composing an email.</p> <p>If I have 3 recipients (for example), run the sort macro, and then remove a recipient from the To: text box, running the macro a second time causes the removed recipient to re-appear. When I step through the macro on the second run, I can see that both <code>.CurrentItem.To</code> and the <code>Recipients</code> object still have all 3 recipients.</p> <p>It is intermittent. Is there any way to force the <code>Recipients</code> object to update when the To: text box has been edited?</p> <p>I can't find anything in the <a href="http://msdn.microsoft.com/en-us/library/aa210995%28v=office.11%29.aspx" rel="nofollow noreferrer">Outlook VBA documentation</a> and trial and error has proved fruitless.</p> <p>Code excerpt:</p> <pre class="lang-vb prettyprint-override"><code>Public Sub SortRecipients() With Application.ActiveInspector If TypeOf .CurrentItem Is Outlook.MailItem Then Debug.Print "Before: " Debug.Print "To: " &amp; .CurrentItem.To Debug.Print "# of recipients: " &amp; .CurrentItem.Recipients.Count ' Force an update if recipients have changed (DOESN'T HELP) .CurrentItem.Recipients.ResolveAll Set myRecipients = .CurrentItem.Recipients ' Create objects for To list Dim myRecipient As recipient Dim recipientToList As Object Set recipientToList = CreateObject("System.Collections.ArrayList") ' Create new lists from To line For Each myRecipient In myRecipients recipientToList.Add myRecipient.Name Next ' Sort the recipient lists recipientToList.Sort ' Remove all recipients so we can re-add in the correct order While myRecipients.Count &gt; 0 myRecipients.Remove 1 Wend ' Create new To line Dim recipientName As Variant For Each recipientName In recipientToList myRecipients.Add (recipientName) Next recipientName .CurrentItem.Recipients.ResolveAll End If End With End Sub </code></pre> <h2>Steps to reproduce:</h2> <ol> <li>Add 4 recipients to the "To" line of a new email in Outlook 2007 (click "Check Names" to resolve the addresses.)</li> <li>Run the SortRecipients macro. (Recipients are now sorted)</li> <li>Delete one recipient, re-run the SortRecipients macro.</li> <li>After doing this, I still have 4 recipients (the deleted one returns).</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload