Link userform to the outlook global address list

maramiro

Board Regular
Joined
Mar 17, 2009
Messages
67
Hello,
I have a userform and i m trying to link the contact dropbox of the userform to the outlook global adress list.
the following code doesnt give me the global adress list, it only provides me my personnel contact list.
Does anyone know how to twist the code to make it global instead of personnel.

Thank you
Code:
Private Sub UserForm_Initialize()
'Outlook objects.
Dim olApp As Outlook.Application
Dim olNamespace As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder
Dim olConItems As Outlook.Items
Dim olItem As Object

'Excel objects.
Dim wbBook As Workbook
Dim wsSheet As Worksheet

'Location in the imported contact list.
Dim lnContactCount As Long
Dim strDummy As String
'Turn off screen updating.
Application.ScreenUpdating = False
'Initialize the Excel objects.
Set wbBook = ThisWorkbook
Set wsSheet = wbBook.Sheets("phonebook")

'Format the target worksheet.
With wsSheet
.Range("A1").CurrentRegion.Clear
.Cells(1, 1).Value = "Name"
.Cells(1, 2).Value = "Title"
With .Range("A1:F1")
.Font.Bold = True
.Font.ColorIndex = 10
.Font.Size = 11
End With
End With
wsSheet.Activate
'Initalize the Outlook variables with the MAPI namespace and the default Outlook folder of the current user.
Set olApp = New Outlook.Application
Set olNamespace = olApp.GetNamespace("MAPI")
Set olFolder = olNamespace.GetDefaultFolder(10)
Set olConItems = olFolder.Items

'Row number to place the new information on; starts at 2 to avoid overwriting the header
lnContactCount = 2
'For each contact: if it is a business contact, write out the business info in the Excel worksheet;
For Each olItem In olConItems
If TypeName(olItem) = "ContactItem" Then
With olItem
If InStr(olItem.CompanyName, strDummy) > 0 Then
Cells(lnContactCount, 1).Value = .LastNameAndFirstName
Cells(lnContactCount, 2).Value = .JobTitle

End If
End With
lnContactCount = lnContactCount + 1
End If
Next olItem
'Null out the variables.
Set olItem = Nothing
Set olConItems = Nothing
Set olFolder = Nothing
Set olNamespace = Nothing
Set olApp = Nothing
'Sort the rows alphabetically using the CompanyName or FullName as appropriate, and then autofit.
With wsSheet
.Range("A2", Cells(2, 6).End(xlDown)).Sort key1:=Range("A2"), order1:=xlAscending
.Range("A:B").EntireColumn.AutoFit
End With
'Turn screen updating back on.
Application.ScreenUpdating = True
Worksheets("MENU").Select

End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
this code is actually working :) when i do it as it on the sheet 1 combobox.
but instead of creating the code on the combobox of sheet1 ,
I would like to do it on my userform combobox.
my combobox is called "ownerbox" in the userform.
Thanks a lot

Code:
Sub GetFromGlobalAddressList()
'write the default Outlook contact name list to the active worksheet
Dim OlApp As Object
Dim OlList As Object
Dim OlAds As Object
Dim Larray() As String
Dim i As Long
Set OlApp = CreateObject("Outlook.Application")
Set OlList = OlApp.GetNamespace("MAPI").AddressLists("Global Address List")
Set OlAds = OlList.AddressEntries
With Sheet1.ComboBox1
.Clear 'clear old address list
ReDim Larray(OlAds.Count)
For i = 1 To OlAds.Count
Larray(i) = OlAds(i)
Next i
.List() = Larray
End With
Set OlApp = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,049
Messages
6,122,864
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top