Guest User

Untitled

a guest
Oct 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. Sub GALExport()
  2.  
  3. Dim appOL As Object
  4. Dim oGAL As Object
  5. Dim oContact As Object
  6. Dim oUser As Object
  7. Dim arrUsers(1 To 65000, 1 To 5) As String
  8. Dim UserIndex As Long
  9. Dim i As Long
  10.  
  11. Set appOL = CreateObject("Outlook.Application")
  12. Set oGAL = appOL.GetNameSpace("MAPI").AddressLists("Global Address List").AddressEntries
  13.  
  14. For i = 1 To oGAL.Count
  15. Set oContact = oGAL.Item(i)
  16. If oContact.AddressEntryUserType = 0 Then
  17. Set oUser = oContact.GetExchangeUser
  18. If Len(oUser.lastname) > 0 Then
  19. UserIndex = UserIndex + 1
  20. arrUsers(UserIndex, 1) = oUser.Name
  21. arrUsers(UserIndex, 2) = oUser.PrimarySMTPAddress
  22. arrUsers(UserIndex, 3) = oUser.Alias
  23. arrUsers(UserIndex, 4) = oUser.JobTitle
  24. arrUsers(UserIndex, 5) = oUser.Department
  25. End If
  26. End If
  27. Next i
  28.  
  29. appOL.Quit
  30.  
  31. Range("A1").Value = "Name"
  32. Range("B1").Value = "Email Address"
  33. Range("C1").Value = "Network Alias"
  34. Range("D1").Value = "Job Title"
  35. Range("E1").Value = "Department"
  36.  
  37. If UserIndex > 0 Then
  38. Range("A2").Resize(UserIndex, UBound(arrUsers, 2)).Value = arrUsers
  39. End If
  40.  
  41. Set appOL = Nothing
  42. Set oGAL = Nothing
  43. Set oContact = Nothing
  44. Set oUser = Nothing
  45. Erase arrUsers
  46.  
  47. End Sub
Add Comment
Please, Sign In to add comment