• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Use VBA to Create a List of Exchange GAL Members

Slipstick Systems

› Developer › Code Samples › Use VBA to Create a List of Exchange GAL Members

Last reviewed on September 10, 2022     19 Comments

How do I print a list of everyone in the Exchange Global Address List (GAL) ?

The recommended way to create a printed address list containing members of the Global Address List is to create contacts for just the people whose information you need and print it from Contacts. To do this, right-click on the entry or entries and choose Add to Contacts.

The macros on this page create an email message containing the name, alias, email address and phone number of members in an Exchange Global Address List or members of an Exchange Distribution Group. Once in Outlook, the list can be printed or copied to another program (such as Excel or Word.)
Printed Exchange GAL

Warning: It can take a long time to create a list from a large Global Address List.

List All GAL Members

Sub GetAllGALMembers()

Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim olGAL As Outlook.AddressList
Dim olEntry As Outlook.AddressEntries
Dim olMember As Outlook.AddressEntry
Dim objMail As Outlook.MailItem

Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olGAL = olNS.GetGlobalAddressList()

Set objMail = olApp.CreateItem(olMailItem)
objMail.Body = "Name" & vbTab & "Alias" & vbTab & "Email Address" & vbTab & "Business Phone" & vbCrLf
Set olEntry = olGAL.AddressEntries
On Error Resume Next
' loop through dist list and extract members
Dim i As Long
For i = 1 To olEntry.Count
  Set olMember = olEntry.Item(i)
  
  If olMember.AddressEntryUserType = olExchangeUserAddressEntry Then
  strName = olMember.Name
  strAlias = olMember.GetExchangeUser.Alias
  strAddress = olMember.GetExchangeUser.PrimarySmtpAddress
  strPhone = olMember.GetExchangeUser.BusinessTelephoneNumber
  objMail.Body = objMail.Body & strName & vbTab & " (" & strAlias & ") " & vbTab & strAddress & vbTab & strPhone & vbCrLf
  End If
Next i

objMail.Display

End Sub

 

List Members of a Distribution list

This macro lists the email address and phone numbers of the members of a specific Exchange distribution group.

Sub GetDGMembers()

Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim olAL As Outlook.AddressList
Dim olEntry As Outlook.AddressEntry
Dim olMember As Outlook.AddressEntry
Dim lMemberCount As Long
Dim objMail As Outlook.MailItem

Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olAL = olNS.AddressLists("Global Address List")

Set objMail = olApp.CreateItem(olMailItem)

' enter the list name
Set olEntry = olAL.AddressEntries("Advertiser Inquiries") 

' get count of dist list members
lMemberCount = olEntry.Members.Count

' loop through dist list and extract members
Dim i As Long
For i = 1 To lMemberCount
  Set olMember = olEntry.Members.Item(i)
  strName = olMember.Name
  strAddress = olMember.GetExchangeUser.PrimarySmtpAddress
  strPhone = olMember.GetExchangeUser.BusinessTelephoneNumber
  
  objMail.Body = objMail.Body & strName & " -- " & strAddress & " -- " & strPhone & vbCrLf
Next i

objMail.Display

End Sub

GAL to Excel

This Outlook macro writes the GAL entries to an Excel workbook. A version of this macro that runs from Excel is at "Use VBA to Export Exchange GAL to Excel".

 Private Const xlUp As Long = -4162
 Sub CopyGALToExcel()
'This is an Outlook Macro
 Dim xlApp As Object
 Dim xlWB As Object
 Dim xlSheet As Object
 Dim bXStarted As Boolean
 
 
Dim i As Long, j As Long, lastRow As Long
Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim olGAL As Outlook.AddressList
Dim olEntry As Outlook.AddressEntries
Dim olMember As Outlook.AddressEntry

Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olGAL = olNS.GetGlobalAddressList()

              
'the path of the workbook
 strPath = "d:\Documents\Book1.xlsx"
     On Error Resume Next
     Set xlApp = GetObject(, "Excel.Application")
     If Err <> 0 Then
         Application.StatusBar = "Please wait while Excel source is opened ... "
         Set xlApp = CreateObject("Excel.Application")
         bXStarted = True
     End If
     On Error GoTo 0
     'Open the workbook to input the data
     Set xlWB = xlApp.Workbooks.Open(strPath)
     Set xlSheet = xlWB.Sheets("Sheet1")

    'Find the next empty line of the worksheet
'clear all current entries
xlSheet.Cells.Select
xlApp.Selection.ClearContents

'set and format headings in the worksheet:
xlSheet.Cells(1, 1).Value = "First Name"
xlSheet.Cells(1, 2).Value = "Last Name"
xlSheet.Cells(1, 3).Value = "Phone/Ext"
xlSheet.Cells(1, 4).Value = "Email"
xlSheet.Cells(1, 5).Value = "Title"
xlSheet.Cells(1, 6).Value = "Department"

With xlSheet.Range("A1:F1")

.Font.Bold = True
.HorizontalAlignment = xlCenter

End With

Set olEntry = olGAL.AddressEntries
On Error Resume Next
'first row of entries
j = 2

' loop through dist list and extract members
For i = 1 To olEntry.Count

Set olMember = olEntry.Item(i)

If olMember.AddressEntryUserType = olExchangeUserAddressEntry Then
'add to worksheet
xlSheet.Cells(j, 1).Value = olMember.GetExchangeUser.LastName
xlSheet.Cells(j, 2).Value = olMember.GetExchangeUser.FirstName
xlSheet.Cells(j, 3).Value = olMember.GetExchangeUser.BusinessTelephoneNumber
xlSheet.Cells(j, 4).Value = olMember.GetExchangeUser.PrimarySmtpAddress
xlSheet.Cells(j, 5).Value = olMember.GetExchangeUser.JobTitle
xlSheet.Cells(j, 6).Value = olMember.GetExchangeUser.Department
j = j + 1
End If
Next i

'determine last data row, basis column B (contains Last Name):
lastRow = xlSheet.Cells(Rows.Count, "B").End(xlUp).Row

'format worksheet data area:
xlSheet.Range("A2:F" & lastRow).Sort Key1:=xlSheet.Range("B2"), Order1:=xlAscending
xlSheet.Range("A2:F" & lastRow).HorizontalAlignment = xlLeft
xlSheet.Columns("A:F").EntireColumn.AutoFit

     xlWB.Close 1
     If bXStarted Then
         xlApp.Quit
     End If
     Set xlApp = Nothing
     Set xlWB = Nothing
     Set xlSheet = Nothing
 End Sub

This table lists the fields that would be useful in these macros. See ExchangeUser members for the complete list.

Field nameDescription
AddressThe X400 e-mail address of the Exchange User
AddressEntryUserTypeReturns olExchangeUserAddressEntry which represents the user type of
the ExchangeUser
AliasThe user's alias
AssistantNameName of the user's assistant
BusinessTelephoneNumberBusiness telephone number
CityCity
CommentsComments in the GAL entry
CompanyNameThe name in the Company field
DepartmentThe department field
DisplayTypeReturns olUser from the OlDisplayType representing the nature of the
ExchangeUser
FirstNameThe user's first name
JobTitleThe job title of the user
LastNameThe last name of the ExchangeUser
MobileTelephoneNumberThe mobile telephone number
NameReturns the display name for the ExchangeUser object
OfficeLocationThe office location field
PostalCodePostal code
PrimarySmtpAddressThe primary Simple Mail Transfer Protocol (SMTP) address
StateOrProvinceState or province
StreetAddressStreet address

This table lists some of the acceptable Address Types. See OlAddressEntryUserType enumeration for the complete list.

Address TypeDescription
olExchangeUserAddressEntryAn Exchange mailbox; includes users, rooms, resources.
olExchangeDistributionListAddressEntryAn Exchange distribution list.
olExchangePublicFolderAddressEntryExchange Public Folder

How to use macros

First: You will need macro security set to low during testing.

To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

More information as well as screenshots are at How to use the VBA Editor

More Information

Extract the members of an Outlook Distribution List to a Word document (VBA Macro)
Get All Email Addresses used on Exchange Server (PowerShell cmdlet)
How to Print an Exchange Distribution List
How to Print Outlook Address Books

Use VBA to Create a List of Exchange GAL Members was last modified: September 10th, 2022 by Diane Poremsky

Related Posts:

  • Use VBA to Export Exchange GAL to Excel
  • How to Import Appointments into a Group Calendar
  • Create Appointments Using Spreadsheet Data
  • Use VBA to create a Mail Merge from Excel

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
19 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Eric (@guest_220224)
April 12, 2023 2:35 am
#220224

what is the field name for country/region?

0
0
Reply
Matt Mason (@guest_219665)
August 25, 2022 10:16 am
#219665

Thank you for taking the time to post this. It was very helpful.

0
0
Reply
Dharm (@guest_213980)
September 21, 2019 10:25 am
#213980

Hi,

When I run a code to list the members of a distribution list, I get a Runtime error '-2147467259 (8004005)' at the below line:

Set olMember = olEntry.Members.Item(i)

What could be the problem?

0
0
Reply
aSystemOverload (@guest_204503)
February 10, 2017 5:29 am
#204503

I'm trying to pull the members of a DG into an access table and it worked last week, but now it's not liking it half way thru, lMemberCount = olEntry.Members.Count says 53, but get to 36 and olEntry.Members.Item(36).GetExchangeUser.Name gives me 91 - Object variable or With block variable not set

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  aSystemOverload
May 30, 2017 1:12 pm
#206857

Sorry i missed this earlier. Did you get it solved? Do you know what entry is #36?

0
0
Reply
Dave (@guest_203001)
November 18, 2016 9:12 am
#203001

Great macros! I'm getting run-time error 287: application-defined or object-defined error on Set olEntry = olGAL.AddressEntries of the GetAllGALMembers subfunction. I added the MS outlook 12.0 object library. What am I missing? I'm sure it is simple. Any further help is greatly appreciated.

0
0
Reply
Pooja (@guest_202381)
October 18, 2016 3:22 pm
#202381

How to look for details (job title, department) of a particular email address in GAL?

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Pooja
October 19, 2016 1:33 am
#202399

The first macro on the pages gets all entries in the gal - the fields you can lookup are listed at the bottom of the page. The big thing is you need to look up the contact before you can get any values.

0
0
Reply
Pooja (@guest_202182)
October 10, 2016 9:14 am
#202182

Hey! I wanted to know if there is a way to get the email sender's details directly from GAL.
I am not able to get the details for senders who are in GAL but not in my local address book.
Thanks.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Pooja
October 19, 2016 1:32 am
#202398

You'd need to look it in the gal using the address, then yes.

0
0
Reply
Pooja (@guest_202403)
Reply to  Diane Poremsky
October 19, 2016 8:02 am
#202403

Any direct method to look up other details in GAL considering email address as search keyword?

0
0
Reply
Pooja (@guest_202166)
October 9, 2016 10:25 am
#202166

My code as below: Public Sub DisplaySenderDetails() Dim Sender As Outlook.AddressEntry Dim xlApp As Object Dim xlWB As Object Dim xlSheet As Object Dim rCount As Long Dim bXStarted As Boolean Dim enviro As String Dim strPath As String Dim strColB, strColC, strColD, strColE, strColF, strColG As String Dim objOL As Outlook.Application Dim objItems As Outlook.Items Dim objFolder As Outlook.MAPIFolder Dim obj As Object Dim objNS As Outlook.NameSpace Dim olItem As Outlook.MailItem Dim strdate As String Dim oExUser As Outlook.ExchangeUser Dim olGAL As Outlook.AddressList Dim olEntry As Outlook.AddressEntries ' Code to set up excel Set objNS = GetNamespace("MAPI") Set olGAL = objNS.GetGlobalAddressList() Set objFolder = objNS.GetDefaultFolder(olFolderInbox).Folders("Abc") Set objItems = objFolder.Items Set olEntry = olGAL.AddressEntries For Each obj In objItems With obj Set Sender = obj.Sender Set olItem = obj If TypeName(obj) = "MailItem" Then On Error Resume Next Dim i As Long For i = 1 To olEntry.Count If olEntry.Item.Address = Sender.Address Then Set oExUser = Sender.GetExchangeUser rCount = xlSheet.Range("B" & xlSheet.Rows.Count).End(-4162).Row rCount = rCount + 1 strdate = DateValue(olItem.ReceivedTime) If strdate >= #7/1/2016# Then strColB = Sender.Name strColC = oExUser.JobTitle strColD = oExUser.Department strColE = oExUser.PrimarySmtpAddress strColF = olItem.Subject strColG = olItem.ReceivedTime ' code to export the data in… Read more »

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 30 Issue 15

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Use Classic Outlook, not New Outlook
  • How to Remove the Primary Account from Outlook
  • Disable "Always ask before opening" Dialog
  • Adjusting Outlook's Zoom Setting in Email
  • This operation has been cancelled due to restrictions
  • Remove a password from an Outlook *.pst File
  • Reset the New Outlook Profile
  • Maximum number of Exchange accounts in an Outlook profile
  • Save Attachments to the Hard Drive
  • How to Hide or Delete Outlook's Default Folders
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
  • Classic Outlook is NOT Going Away in 2026
  • Use PowerShell to Delete Attachments
  • Remove RE:, FWD:, and Other Prefixes from Subject Line
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Classic Outlook is NOT Going Away in 2026

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Newest Code Samples

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

Use PowerShell or VBA to get Outlook folder creation date

Rename Outlook Attachments

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment