hi All

I was wondering whether someone can help me with the following as I am new to vba.

I need to write a code that extracts the distribution list names and its members from Outlook and exports it into an excel spreadsheet.

Is this something that is relatively easy to do?

I found the following code in google but need to modify it so it just search through all in one go rather than specifying the name of the list and then export it into an excel sheet which is on g:\names.xlsx

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
The code above works from outlook however [I] would like to run this from excel and ti return list names and its members and count of how many people in each list.

Thnaks in advance