Results 1 to 8 of 8

Thread: Excel VBA Macro to Extract Outlook GAL Email Address Using Alias

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10

    Hi showtime,

    Welcome to ExcelFox. Code below. If you want the working file, check out the attachment.

    Code:
    Option Explicit
    
    Sub GetExchangeUserDetailsFromAlias()
        
        Dim str As String
        Dim olApp As Object 'Outlook.Application
        Dim olNameSpace As Object 'Outlook.Namespace
        Dim olRecipient As Object 'Outlook.Recipient
        Dim oEU As Object 'Outlook.ExchangeUser
        Dim arrUsers(1 To 65000, 1 To 3) As String
        Dim lngUser As Long
        Dim rngAlias As Range, rngAliasList As Range
        
        On Error Resume Next
        Set olApp = GetObject(, "Outlook.Application")
        If olApp Is Nothing Then
            Set olApp = CreateObject("Outlook.Application")
        End If
        On Error GoTo 0
        
        Set olNameSpace = olApp.GetNamespace("MAPI")
        
        With Worksheets("Users")
            Set rngAliasList = .Range("rngAliasList")
        End With
        For Each rngAlias In rngAliasList
            lngUser = lngUser + 1
            If Len(rngAlias.Value) > 0 Then
                str = rngAlias.Value
                Set olRecipient = olNameSpace.CreateRecipient(str)
                olRecipient.Resolve
                If olRecipient.Resolved Then
                    If olRecipient.AddressEntry.AddressEntryUserType = 0 Then 'olExchangeUserAddressEntry
                        Set oEU = olRecipient.AddressEntry.GetExchangeUser
                        If Not (oEU Is Nothing) Then
                            With oEU
                                arrUsers(lngUser, 1) = .PrimarySmtpAddress
                                arrUsers(lngUser, 2) = .Name
                                arrUsers(lngUser, 3) = .MobileTelephoneNumber
                            End With
                        End If
                    End If
                End If
            End If
        Next rngAlias
        rngAliasList.Offset(, 1).Resize(, 3).Value = arrUsers
        
        Set olApp = Nothing 'Outlook.Application
        Set olNameSpace = Nothing 'Outlook.Namespace
        Set olRecipient = Nothing 'Outlook.Recipient
        Set oEU = Nothing 'Outlook.ExchangeUser
        If lngUser Then Erase arrUsers
        Set rngAlias = Nothing
        Set rngAliasList = Nothing
        
    End Sub
    Attached Files Attached Files
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

Similar Threads

  1. VBA To Extract Email Address From Text
    By dunndealpr in forum Excel Help
    Replies: 43
    Last Post: 06-05-2019, 03:56 PM
  2. Excel macro to get GAL from outlook.
    By superman in forum Excel Help
    Replies: 2
    Last Post: 09-05-2014, 10:14 AM
  3. Extract Outlook 2007 global address List in excel 2007
    By superman in forum Outlook Help
    Replies: 0
    Last Post: 09-03-2014, 07:15 PM
  4. Replies: 2
    Last Post: 05-23-2013, 08:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •