none
Check Names across Multiple Emails RRS feed

  • Question

  • Hello all, I have a script that generates a large number of emails into my outlook drafts, with the names of the recipients in the 'to' line. These names match exactly what is contained in my outlook address book, and I would like to use the check names feature to check all of them and get their email addresses, however when highlighting all the emails the check names feature will only check the first email in the list. Is there a way to make check names check all the emails in the list? Or will I have to write a macro to perform this function? I am a complete beginner when it comes to VBA, so if anyone could help me with the macro or point me to any resources that will help me with writing this macro (if it is necessary) it would be much appreciated. Thank you!
    Monday, February 6, 2017 2:49 PM

Answers

  • Hello,

    After the message is saved you can check out the Recipients collection which provides the ResolveAll method. It attempts to resolve all the Recipient objects in the Recipients collection against the Address Book. 

    Sub CheckRecipients()  
     Dim MyItem As Outlook.MailItem  
     Dim myRecipients As Outlook.Recipients  
     Dim myRecipient As Outlook.Recipient 
     Set myItem = Application.CreateItem(olMailItem)  
     Set myRecipients = myItem.Recipients  
     myRecipients.Add("Eugene Astafiev")  
     myRecipients.Add("Nate Sun")  
     myRecipients.Add("Dan Wilson") 
     If Not myRecipients.ResolveAll Then  
     For Each myRecipient In myRecipients  
     If Not myRecipient.Resolved Then  
     MsgBox myRecipient.Name  
     End If  
     Next  
     End If  
    End Sub

    Also you may consider using the Resolve method of the Recipient class which attempts to resolve a Recipient object against the Address Book.  

    Sub AssignTask()  
     Dim myItem As Outlook.TaskItem  
     Dim myDelegate As Outlook.Recipient 
     Set MyItem = Application.CreateItem(olTaskItem)  
     MyItem.Assign  
     Set myDelegate = MyItem.Recipients.Add("Eugene Astafiev")  
     myDelegate.Resolve  
     If myDelegate.Resolved Then  
     myItem.Subject = "Prepare Agenda For Meeting"  
     myItem.DueDate = Now + 30  
     myItem.Display  
     myItem.Send  
     End If  
    End Sub

    Finally, you may find the How To: Fill TO,CC and BCC fields in Outlook programmatically article helpful.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    • Marked as answer by BagoSnakes Monday, February 6, 2017 3:39 PM
    Monday, February 6, 2017 3:33 PM

All replies

  • Hello,

    After the message is saved you can check out the Recipients collection which provides the ResolveAll method. It attempts to resolve all the Recipient objects in the Recipients collection against the Address Book. 

    Sub CheckRecipients()  
     Dim MyItem As Outlook.MailItem  
     Dim myRecipients As Outlook.Recipients  
     Dim myRecipient As Outlook.Recipient 
     Set myItem = Application.CreateItem(olMailItem)  
     Set myRecipients = myItem.Recipients  
     myRecipients.Add("Eugene Astafiev")  
     myRecipients.Add("Nate Sun")  
     myRecipients.Add("Dan Wilson") 
     If Not myRecipients.ResolveAll Then  
     For Each myRecipient In myRecipients  
     If Not myRecipient.Resolved Then  
     MsgBox myRecipient.Name  
     End If  
     Next  
     End If  
    End Sub

    Also you may consider using the Resolve method of the Recipient class which attempts to resolve a Recipient object against the Address Book.  

    Sub AssignTask()  
     Dim myItem As Outlook.TaskItem  
     Dim myDelegate As Outlook.Recipient 
     Set MyItem = Application.CreateItem(olTaskItem)  
     MyItem.Assign  
     Set myDelegate = MyItem.Recipients.Add("Eugene Astafiev")  
     myDelegate.Resolve  
     If myDelegate.Resolved Then  
     myItem.Subject = "Prepare Agenda For Meeting"  
     myItem.DueDate = Now + 30  
     myItem.Display  
     myItem.Send  
     End If  
    End Sub

    Finally, you may find the How To: Fill TO,CC and BCC fields in Outlook programmatically article helpful.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    • Marked as answer by BagoSnakes Monday, February 6, 2017 3:39 PM
    Monday, February 6, 2017 3:33 PM
  • Thank you, that is exactly what I needed!
    Monday, February 6, 2017 3:39 PM