title: Retrieve Outlook details based on alias name Excel VBA
body: <p>I have a list Employee IDs of all the employees in my organization. I want Excel VBA code to get details like first name, last name, designation contact# and department.</p>
  
  <p>The alias name is the Employee ID. So the code should take the Employee ID as alias and search Outlook for the respective details as mentioned above.</p>
  
  <p>I found a macro online and modified it to my requirement:</p>
  
  <pre><code>Sub tgr()
  
  Dim appOL As Object
  Dim oGAL As Object
  Dim oContact As Object
  Dim oUser As Object
  Dim UserIndex As Long
  Dim i As Long
  Dim j As Integer
  
  Set appOL = CreateObject("Outlook.Application")
  Set oGAL = appOL.GetNamespace("MAPI").AddressLists("/Name of the Distribution List/").AddressEntries
  
  On Error Resume Next
  
  For j = 2 To Application.WorksheetFunction.CountA(Columns(1))
  
      For i = 1 To oGAL.Count
  
          Set oContact = oGAL.Item(i)
  
          If oContact.AddressEntryUserType = 0 Then
  
              Set oUser = oContact.GetExchangeUser
  
              If UCase(oUser.FirstName) = UCase(Range("A" &amp; j).Value) And UCase(oUser.LastName) = UCase(Range("B" &amp; j).Value) Then
  
                  Range("c" &amp; j).Value = oUser.Alias
  
                  Range("D" &amp; j).Value = oUser.JobTitle
  
                  Range("E" &amp; j).Value = oUser.Department
  
                  Range("F" &amp; j).Value = oUser.ManagerName
  
                  i = oGAL.Count
              End If
          End If       
      Next i
  Next j
  
  Set oGAL = Nothing
  Set oContact = Nothing
  Set oUser = Nothing
  
  End Sub
  </code></pre>
  
  <p>The code works but the issue is that it checks all the items in the addresslist everytime to search for each item. This is taking more time. </p>
  
  <p>Is there a way to simplify it by searching broadly instead of looking at each item in the addresslist and comparing. Something like Addresslist.find. Well the propety find only works if searching within a contact folder for addresslist there is no FIND property.</p>