Excel VBA code to extract all outlook global address emails and UserID

Uzma Shaheen

Active Member
Joined
Nov 10, 2012
Messages
484
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
  2. Mobile
  3. Web
Hi All,

Im trying to get outlook global email address and userId in to my workbook

What is the best way to achieve this

Please can you help me

Many many many thanks
 
I think the problem is not writing the data on the sheet, I think it is the time it takes to get the information from Outlook.


But try the following, change 1000 for the number of data you need to extract. It is the only way I found.

Code:
Sub GetOutlookAddressBook()
  Dim objOutlook As Outlook.Application, objAddressList As Outlook.AddressList
  Dim oItem As Outlook.AddressEntry, i As Long, arr, n As Long, num As Long
  Application.ScreenUpdating = False
  Set objOutlook = CreateObject("Outlook.Application")
  Set objAddressList = objOutlook.Session.AddressLists("Global Address List")
  Sheets("Sheet1").Range("A:C").ClearContents
  n = 1
  num = [COLOR=#ff0000]1000[/COLOR]
  ReDim arr(1 To num, 1 To 3)
  On Error Resume Next
  For i = 1 To num
    arr(n, 1) = objAddressList.AddressEntries(i).Name
    arr(n, 2) = objAddressList.AddressEntries(i).GetExchangeUser.Alias
    arr(n, 3) = objAddressList.AddressEntries(i).GetExchangeUser.PrimarySmtpAddress
    n = n + 1
  Next
  Range("A2").Resize(UBound(arr), 3).Value = arr
  Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Thank you

ill give that a go

i have potentially 10k agents to pull back and also I get the outlook security message and as it’s taking longer than 5 minutes, I’m constantly having to press allow after every 5 mins
 
Upvote 0
Try the following, it will show you the item number in statusbar

Code:
Sub GetOutlookAddressBook()
  Dim objOutlook As Outlook.Application, objAddressList As Outlook.AddressList
  Dim oItem As Outlook.AddressEntry, i As Long, arr, n As Long, num As Long
  Application.ScreenUpdating = False
  Application.DisplayAlerts = False
  Application.StatusBar = False
  Set objOutlook = CreateObject("Outlook.Application")
  Set objAddressList = objOutlook.Session.AddressLists("Lista global de direcciones")
  Sheets("Sheet1").Range("A:C").ClearContents
  n = 1
  num = 1000
  ReDim arr(1 To num, 1 To 3)
  On Error Resume Next
  For i = 1 To num
[COLOR=#0000ff]    Application.StatusBar = "Item : " & i[/COLOR]
    arr(n, 1) = objAddressList.AddressEntries(i).Name
    arr(n, 2) = objAddressList.AddressEntries(i).GetExchangeUser.Alias
    arr(n, 3) = objAddressList.AddressEntries(i).GetExchangeUser.PrimarySmtpAddress
    n = n + 1
  Next
  Range("A2").Resize(UBound(arr), 3).Value = arr
  Application.ScreenUpdating = True
  Application.StatusBar = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top