In an Outlook userform, I want to caption a label ("CourrielSup") using an email address selected from the global address list.
Using the SelectNamesDialog.Display
method from the Microsoft knowledge base I get access to the global address book. When I click the command button "ListeAdresse", the dialog box displaying the address book pops up.
I can't find a way to have the selected email address become the caption of my label.
Private Sub ListeAdresse_Click()
Dim Courriel As String
Dim oDialog As SelectNamesDialog
Set oDialog = Application.Session.GetSelectNamesDialog
With oDialog
.InitialAddressList = Application.Session.GetGlobalAddressList
If .Display Then
CourrielSup.Caption = .Recipients
End If
End With
End Sub
This works for me:
Sub ListeAdresse_Click()
Const PR_SMTP_ADDRESS As String = _
"http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
Dim dlg As SelectNamesDialog, recip As Recipient
Set dlg = Application.Session.GetSelectNamesDialog
With dlg
.InitialAddressList = Application.Session.GetGlobalAddressList
If .Display Then
Set recip = .Recipients(1)
'get the address property
Debug.Print recip.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS)
End If
End With
End Sub
GetProperty:
https://learn.microsoft.com/en-us/office/vba/api/outlook.propertyaccessor.getproperty