I am using O365 classic Outlook on Windows 10.
I want to check that every user in "All users" is known in an internal "HR" directory.
In the sample VBA code below, AddressList.AddressEntries
only collects the first 500 entries.
Browsing the "All Users" global list in the Outlook AddressBook window, I see the same last 500th user if I scroll to the end of the list, meaning the displayed list is truncated.
If I search using "Names only" for the 500th user name in AddressBook I see it and the remaining existing users, in my case 40 users as we have currently 539 users.
If I now run now the code, I get 40 entries, but only users displayed in the AddressBook window with its default size (around 15 users), repeated three times (partially for last occurrence).
Sub ExtractExchange()
Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olGAL As Outlook.AddressList
Dim olEntry As Outlook.AddressEntry
Set olApp = CreateObject("Outlook.Application")
Set olNS = olApp.GetNamespace("MAPI")
Set olGAL = olNS.AddressLists("All Users")
For Each olEntry In olGAL.AddressEntries
' some code here
Next olEntry
End Sub
- Changing the size of the AddressBook window does not change this behavior, 15 users repeated.
- When searching with "All columns" I retrieve the 500 first entries.
- I tried
GetFirst
andGetNext
to loop throughAddressEntries
with no observed differences.
How do I go over the 500 entries limit, up to 1000 to be on safe side?
Insight on interactions between searching in AddressBook with "Names only" option and AddressList object would be useful.
Also would the limit be on the server or client side?
I am using O365 classic Outlook on Windows 10.
I want to check that every user in "All users" is known in an internal "HR" directory.
In the sample VBA code below, AddressList.AddressEntries
only collects the first 500 entries.
Browsing the "All Users" global list in the Outlook AddressBook window, I see the same last 500th user if I scroll to the end of the list, meaning the displayed list is truncated.
If I search using "Names only" for the 500th user name in AddressBook I see it and the remaining existing users, in my case 40 users as we have currently 539 users.
If I now run now the code, I get 40 entries, but only users displayed in the AddressBook window with its default size (around 15 users), repeated three times (partially for last occurrence).
Sub ExtractExchange()
Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olGAL As Outlook.AddressList
Dim olEntry As Outlook.AddressEntry
Set olApp = CreateObject("Outlook.Application")
Set olNS = olApp.GetNamespace("MAPI")
Set olGAL = olNS.AddressLists("All Users")
For Each olEntry In olGAL.AddressEntries
' some code here
Next olEntry
End Sub
- Changing the size of the AddressBook window does not change this behavior, 15 users repeated.
- When searching with "All columns" I retrieve the 500 first entries.
- I tried
GetFirst
andGetNext
to loop throughAddressEntries
with no observed differences.
How do I go over the 500 entries limit, up to 1000 to be on safe side?
Insight on interactions between searching in AddressBook with "Names only" option and AddressList object would be useful.
Also would the limit be on the server or client side?
Share Improve this question edited Feb 4 at 15:58 CommunityBot 11 silver badge asked Jan 31 at 13:16 pme35pme35 33 bronze badges1 Answer
Reset to default 0Never loop through any collections in Outlook. For the folder items, you can use Items.Find/FindNext
and Items.Restrict
. For the address book collection, OOM does not expose anything but similar, but you can use Namespace.CreateRecipient
/ Recipient.Resolve
- that will resolve a name (or address) against all containers. This is equivalent to typing a name in the To edit box in Outlook and hitting Ctrl+K.
If you want to resolve against a particular container (e.g. "All Users" GAL container), you would need to use Extended MAPI (C++ or Delphi only). You can use Redemption (I am its author - any language) - it exposes RDOSession.AddressBook.ResolveName
/ ResolveNameEx
and RDOAddresList.ResolveName
/ ResolveNameEx
. You can also use RDOAddressList.Search
to resolve by Name/Department/City etc. - it is the same functionality you see in "Address Book | Tools | Find" in Outlook.
If you need to retrieve data from all entries rather than find a match based on some criteria, you can try to use MAPITable object in Redemption. The script below does that for all rows. You can also try to do it one row at a time
Const PR_DISPLAY_NAME = &H3001001F
Sub test()
dim Columns(0)
set mySession = CreateObject("Redemption.RDOSession")
mySession.MAPIOBJECT = Application.Session.MAPIOBJECT
'BrowseObject(Session.AddressBook)
set Table = mySession.AddressBook.AddressLists(false).Item("All Users").AddressEntries.MAPITable
Columns(0) = PR_DISPLAY_NAME
Table.Columns = Columns
Table.GoToFirst
Rows = Table.GetRows(Table.RowCount)
for i = LBound(Rows)to UBound(Rows)
Row = Rows(i)
Debug.Print(Row(0))
next
Debug.Print i
End sub