title: Find Exchange User's OfficeLocation in VBA
body: <p>When viewing someone's contact card in Outlook, there is a field for Office which gives their location. How can I find that using VBA? Here's my most functional code:</p>
  
  <pre><code>Private Function getLocation(username As String) As String
  Dim olApp As Outlook.Application
  Dim olNS As Outlook.Namespace
  Dim olGAL As Outlook.AddressEntries
  Dim olAddressEntry As Outlook.AddressEntry
  Dim olUser As Outlook.ExchangeUser
  
  Set olApp = New Outlook.Application
  Set olNS = olApp.GetNamespace("MAPI")
  Set olGAL = olNS.AddressLists("Global Address List").AddressEntries
  Set olAddressEntry = olGAL.Item(username)
  Set olUser = olAddressEntry.GetExchangeUser
  Debug.Print olGAL.Count 'count is 646718
  Debug.Print olUser.OfficeLocation
  Debug.Print olUser.Address
  Debug.Print olUser.Name
  
  getLocation = olUser.OfficeLocation
  
  Set olApp = Nothing
  Set olNS = Nothing
  Set olGAL = Nothing
  Set olAddressEntry = Nothing
  Set olUser = Nothing
  
  End Function
  </code></pre>
  
  <p>This works when I search for their actual name (EG, John Smith), but it only returns the first John Smith. How can I use their email address or alias to search?</p>
  
  <p>Note: I added a reference to the <code>Microsoft Outlook 16.0 Object Library</code> to take advantage of Intellisense, but I plan on switching to late binding once it works.</p>