Hi Stefi,
Using Outlook methods, I do not believe
that you interrogate the Global Address
book (GAL) to obtain the department
details.
To return the name and email details, in
the Userform module, try something like:
'=============>>
Option Explicit
Dim arr() As String
Private Sub UserForm_Initialize()
Dim olApp As Outlook.Application
Dim oNS As Outlook.Namespace
Dim oAL As AddressList
Dim oAE As AddressEntry
Dim i As Long
Dim j As Long
With Me.ListBox1
.ColumnCount = 3
.ColumnWidths = "90 pt;72 pt;90 pt"
.TextColumn = -1
End With
On Error GoTo XIT
Set olApp = New Outlook.Application
Set oNS = olApp.GetNamespace("MAPI")
Set oAL = oNS.AddressLists(1)
With Me
For i = 1 To oAL.AddressEntries.Count
Set oAE = oAL.AddressEntries.Item(i)
j = j + 1
ReDim Preserve arr(1 To 3, 1 To j)
With oAE
arr(1, j) = .Name
arr(2, j) = .Address
arr(3, j) = .GetContact
End With
Next i
Me.ListBox1.List() = Application.Transpose(arr)
End With
XIT:
Set oAE = Nothing
Set oAL = Nothing
Set oNS = Nothing
Set olApp = Nothing
End Sub
'----------------->>
Private Sub CommandButton1_Click()
Dim SH As Worksheet
Dim destRng As Range
Set SH = ThisWorkbook.Sheets("Foglio1") '<<=== CHANGE
Set destRng = SH.Range("A" & Rows.Count).End(xlUp)(2)
destRng.Resize(UBound(arr, 2), 2).Value = _
Application.Transpose(arr) 'arr2
End Sub
'<<=============
In order to interrogate the GAL further, see
the techniques used by Pavel Nagaev at:
Import Active Directory user data into Outlook address books
http://www.outlookexchange.com/articles/Pavelnagaev/nagaev_c1p4.asp