Launch Outlook address book dialog box using VBA
<p>I have a button called <code>selectRec</code> that users will click in a userform.</p>

<p>I want that button to be clicked, then their Outlook address book dialog box prompts them to add recipients. The recipients will then be added to <code>ListBox1</code>. The code below only allows one recipient to be added, even if many are selected. It is because it only accesses the 1st item in the <code>oDialog.recipients.Item</code> array. I don't know how to use a for loop to iterate through something I don't know the length of (as they can add as many email addresses as they'd like)</p>

<pre><code>  Private Sub selectRec_Click()

    Dim olApp As Outlook.Application
    Dim oDialog As SelectNamesDialog
    Dim oGAL As AddressList
    Dim myAddrEntry As AddressEntry
    Dim exchUser As Outlook.ExchangeUser

    Dim AliasName As String
    Dim FirstName As String
    Dim LastName As String
    Dim EmailAddress As String

    Set olApp = GetObject(, "Outlook.Application")
    Set oDialog = olApp.Session.GetSelectNamesDialog
    Set oGAL = olApp.GetNamespace("MAPI").AddressLists("Global Address List")

    With oDialog
        .AllowMultipleSelection = True
        .InitialAddressList = oGAL
        .ShowOnlyInitialAddressList = True



        If .Display Then

          AliasName = oDialog.recipients.Item(1).Name

            Set myAddrEntry = oGAL.AddressEntries(AliasName)
            Set exchUser = myAddrEntry.GetExchangeUser

            If Not exchUser Is Nothing Then
                FirstName = exchUser.FirstName
                LastName = exchUser.LastName
                EmailAddress = exchUser.PrimarySmtpAddress

            End If
            ListBox1.AddItem (EmailAddress)



        End If
    End With
Set olApp = Nothing
Set oDialog = Nothing
Set oGAL = Nothing
Set myAddrEntry = Nothing
Set exchUser = Nothing
End Sub
</code></pre>